Commit cbb4d730 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ added local dependencies and script to import them (flaky)

* TODO: use p2 instead if possible or create fatjar
parent 32e95376
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -6,7 +6,12 @@
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" path="src-gen"/>
	<classpathentry including="**/*.java" kind="src" output="target/classes" path="src-gen">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
@@ -19,9 +24,9 @@
	</classpathentry>
	<classpathentry kind="src" path="target/generated-sources/annotations">
		<attributes>
			<attribute name="ignore_optional_problems" value="true"/>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
			<attribute name="ignore_optional_problems" value="true"/>
			<attribute name="m2e-apt" value="true"/>
		</attributes>
	</classpathentry>
+230 −0
Original line number Diff line number Diff line
#!/usr/bin/python3

# Install to Project Repo
# A script for installing jars to an in-project Maven repository.
#
# v0.1.2
#
# MIT License
# (c) 2012, Nikita Volkov. All rights reserved.
# https://github.com/nikita-volkov/install-to-project-repo
#


import os
import re
import shutil
import argparse


def jars(dir):
  return [dir + "/" + f for f in os.listdir(dir) if f.lower().endswith(".jar")]

def parse_by_eclipse_standard(path):
  file = os.path.splitext(os.path.basename(path))[0]
  print(file)
  match = re.match(r"([\w\.]+)-(\d+\.\d+\.\d+.*)", file)
  if match != None:
    (name, version) = match.group(1, 2)

    name = name.split(".")
    source = name[-1] == "source"
    (group, name) = (".".join(name[:-2]), name[-2]) if source else (".".join(name[:-1]), name[-1])

    snapshot = version.upper().endswith(".SNAPSHOT")
    if snapshot:
      version = version[:-len(".snapshot")]

    return {
      "group": group,
      "name": name,
      "version": version,
      "snapshot": snapshot,
      "source": source
    }

def maven_dependencies(parsing_results):
  def artifact(parsing):
    return {
      "groupId": parsing["group"],
      "artifactId": parsing["name"],
      "version": parsing["version"] + ("-SNAPSHOT" if parsing["snapshot"] else "")
    }
  def maven_dependency(artifact):
    return """
<dependency>
  <groupId>%(groupId)s</groupId>
  <artifactId>%(artifactId)s</artifactId>
  <version>%(version)s</version>
</dependency>
""" % artifact
  def unique_artifacts():
    artifacts = []
    for (_, parsing) in parsing_results:
      a = artifact(parsing)
      if a not in artifacts:
        artifacts.append(a)
    return artifacts

  return "\n".join([maven_dependency(a).strip() for a in unique_artifacts()])


def install(path, parsing):
  os.system(
    "mvn install:install-file" + \
    " -Dfile=" + path + \
    " -DgroupId=" + parsing["group"] + \
    " -DartifactId=" + parsing["name"] + \
    " -Dversion=" + parsing["version"] + ("-SNAPSHOT" if parsing["snapshot"] else "") + \
    " -Dpackaging=jar" + \
    " -DlocalRepositoryPath=repo" + \
    " -DcreateChecksum=true" + \
    (" -Dclassifier=sources" if parsing["source"] else "")
  )


def splits(str, splitter):
  parts = str.split(splitter)
  def split(i):
    (l, r) = splitAt(parts, i)
    return (splitter.join(l), splitter.join(r))

  return map(split, range(1, len(parts)))

def splitAt(list, i):
  if i <= 0:
    return ([], list)
  elif i >= len(list):
    return (list, [])
  else:
    return (list[:i], list[i:])

def name_to_version_alternatives(filename):
  return [
    (n, v)
    for (n, v) in list(splits(filename, "-")) + list(splits(filename, "_"))
    if v.lower() not in ["sources", "src", "snapshot"]
  ]

def group_to_name_alternatives(group):
  return [
    (n, v)
    for (n, v) in splits(group, ".")
    if (v.lower()) not in ["source", "snapshot"]
  ]

def version_parsing(version):

  def f(version, splitter, ending):
    parts = version.split(splitter)
    if parts[-1] == ending:
      return (splitter.join(parts[:-1]), True)
    else:
      return (version, False)

  (version, source) = f(version, "-", "sources")
  (version, snapshot) = f(version, "-", "SNAPSHOT")
  if not snapshot:
    (version, snapshot) = f(version, ".", "SNAPSHOT")

  return version, snapshot, source

def name_parsing(name):
  if name.endswith(".source"):
    return name[:-len(".source")], True
  else:
    return name, False

def unzip(l):
  return tuple(zip(*l))

def input_choice(labels, values):
  for (i, v) in enumerate(labels):
    print("%d) %s" % (i+1, v))
  while True:
    try:
      i = input()
      i = int(i)
      return values[i-1]
    except ValueError:
      print("Incorrect input: `%s` is not a number. Try again" % i)
    except IndexError:
      print("Incorrect input: `%s` is out of range. Try again" % i)


def parse_interactively(path):
  filename = os.path.splitext(os.path.basename(path))[0]

  print("-----")
  print("Processing `%s`" % path)

  alternatives = name_to_version_alternatives(filename)
  alternatives.sort(key=lambda n: len(n[1]))

  if not alternatives:
    print("Incorrect name format: `%s`. Skipping" % filename)
    return
  if len(alternatives) > 1:
    print("Choose a correct version for `%s`:" % filename)
    labels = [version_parsing(v)[0] for v in unzip(alternatives)[1]]
    (name, version) = input_choice(labels, alternatives)
  else:
    (name, version) = alternatives[0]


  alternatives = list(reversed(group_to_name_alternatives(name)))
  if not alternatives:
    print("Incorrect name format: `%s`. Skipping" % filename)
    return
  if len(alternatives) > 1:
    print("Choose a correct artifactId for `%s`:" % name)
    labels = [name_parsing(a)[0] for a in unzip(alternatives)[1]]
    (group, name) = input_choice(labels, alternatives)
  else:
    (group, name) = alternatives[0]


  version, snapshot, source = version_parsing(version)
  name, source1 = name_parsing(name)

  return {
    "group": group,
    "name": name,
    "version": version,
    "snapshot": snapshot,
    "source": source or source1
  }

parser = argparse.ArgumentParser(description='Installer for jars to an in-project Maven repository')
parser.add_argument('-i', '--interactive',
                    dest='interactive', action='store_true', default=False,
                    help='Interactively resolve ambiguous names. Use this option to install libraries of different naming standards')
parser.add_argument('-d', '--delete',
                    dest='delete', action='store_true', default=False,
                    help='Delete successfully installed libs in source location')

args = parser.parse_args()


parsings = (
  [(path, parse_interactively(path)) for path in jars("lib")]
  if args.interactive else
  [(path, parse_by_eclipse_standard(path)) for path in jars("lib")]
)

unparsable_files = [r[0] for r in parsings if r[1] == None]
if unparsable_files:
  print("The following files could not be parsed:")
  for f in unparsable_files:
    print("| - " + f)
  print("Make sure the files are in the following format: groupId.artifactId[.source]_version[.SNAPSHOT].jar")


parsings = [p for p in parsings if p[1] != None]

for (path, parsing) in parsings:
  install(path, parsing)
  if args.delete:
    os.remove(path)

print(maven_dependencies(parsings))
 No newline at end of file
+178 −3
Original line number Diff line number Diff line
@@ -9,7 +9,16 @@
	</parent>
	<artifactId>org.etsi.mts.tdl.tx.web</artifactId>
	<packaging>war</packaging>

<repositories>
        <repository>
        <id>local-dependencies</id>
        <url>file://${project.basedir}/repo</url>
        </repository>        
    </repositories>
	<properties>
	      <!-- The main class to start by executing "java -jar" -->
	      <!-- <start-class>org.etsi.mts.tdl.web.ServerLauncher</start-class> -->
	</properties>
	<build>
		<sourceDirectory>src</sourceDirectory>
		<resources>
@@ -28,10 +37,20 @@
			</plugin>
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.3.2</version>
				<version>3.4.0</version>
				<configuration>
					<warSourceDirectory>WebRoot</warSourceDirectory>
					<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- <archiveClasses>true</archiveClasses> -->
					<archive>
			            <manifest>
			                <!-- 
			                -->
			                <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                	        <mainClass>org.etsi.mts.tdl.web.ServerLauncher</mainClass>
			            </manifest>
			        </archive>
				</configuration>
			</plugin>
			<plugin>
@@ -72,8 +91,12 @@
			</plugin>
		</plugins>
	</build>

	<dependencies>
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.etsi.mts.tdl.model</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.etsi.mts.tdl.tx</artifactId>
@@ -84,6 +107,11 @@
			<artifactId>org.etsi.mts.tdl.tx.ide</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.etsi.mts.tdl.helper</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>org.eclipse.xtext.xbase.web</artifactId>
@@ -126,5 +154,152 @@
			<version>2.0.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-server</artifactId>
			<version>11.0.15</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-webapp</artifactId>
			<version>11.0.15</version>
		</dependency>
<!-- <dependency>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-runner</artifactId>
			<version>11.0.15</version>
		</dependency> -->
		<dependency>
			<groupId>org.eclipse.platform</groupId>
			<artifactId>org.eclipse.core.resources</artifactId>
			<version>3.20.100</version>
</dependency>

		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.etsi.mts.tdl.TDLan2</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.etsi.mts.tdl.TPLan2</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.etsi.mts.tdl.txi</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>org.etsi.mts.tdl.common</artifactId>
			<version>${project.version}</version>
		</dependency>

            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.ocl.xtext.base</artifactId>
            <version>1.18.0.v20221201-0557</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.ocl.common</artifactId>
            <version>1.18.0.v20221201-0557</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.ocl.pivot</artifactId>
            <version>1.18.0.v20221201-0557</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.ocl.pivot.uml</artifactId>
            <version>1.18.0.v20221201-0557</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.ocl.xtext.completeocl</artifactId>
            <version>1.18.0.v20221201-0557</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.ocl.xtext.essentialocl</artifactId>
            <version>1.18.0.v20221201-0557</version>
            </dependency>

            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.emf.edit</artifactId>
            <version>2.19.0.v20230828-0616</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.emf.mwe.core</artifactId>
            <version>1.9.0.v20230826-1559</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.emf.mwe2.runtime</artifactId>
            <version>2.15.0.v20230826-1559</version>
            </dependency>
            <dependency>
            <groupId>org</groupId>
            <artifactId>eclipse.emf.mwe.utils</artifactId>
            <version>1.9.0.v20230826-1559</version>
            </dependency>
<dependency>
  <groupId>org.eclipse.epsilon.eol</groupId>
  <artifactId>tools</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon.erl</groupId>
  <artifactId>engine</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon.common</groupId>
  <artifactId>dt</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon.evl.emf</groupId>
  <artifactId>validation</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon</groupId>
  <artifactId>profiling</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon.etl</groupId>
  <artifactId>engine</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon.evl</groupId>
  <artifactId>engine</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon.emc</groupId>
  <artifactId>emf</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon</groupId>
  <artifactId>common</artifactId>
  <version>2.4.0.202203041826</version>
</dependency>
<dependency>
  <groupId>org.eclipse.epsilon.eol</groupId>
  <artifactId>engine</artifactId>
  <version>2.4.0.202203041826</version>
		</dependency>

	</dependencies>
</project>
+302 KiB

File added.

No diff preview for this file type.

+1 −0
Original line number Diff line number Diff line
13d723be6c67cefa037b1af8cc32e46e
 No newline at end of file
Loading