The Unified and Autonomous Development Platform
Make plugin.maven a separate project
robin shine0dcc809cff5f
diff --git a/plugin.maven/.gitignore b/plugin.maven/.gitignoredeleted file mode 100644index ea8c4bf7f3..0000000000--- a/plugin.maven/.gitignore+++ /dev/null@@ -1 +0,0 @@-/targetdiff --git a/plugin.maven/pom.xml b/plugin.maven/pom.xmldeleted file mode 100644index 9da8c0fd9c..0000000000--- a/plugin.maven/pom.xml+++ /dev/null@@ -1,172 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">- <modelVersion>4.0.0</modelVersion>- <groupId>com.gitplex</groupId>- <artifactId>plugin.maven</artifactId>- <version>1.0-EAP-build18</version>- <packaging>maven-plugin</packaging>- <prerequisites>- <maven>${mavenVersion}</maven>- </prerequisites>- <build>- <finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>- <pluginManagement>- <plugins>- <plugin>- <groupId>org.eclipse.m2e</groupId>- <artifactId>lifecycle-mapping</artifactId>- <version>1.0.0</version>- <configuration>- <lifecycleMappingMetadata>- <pluginExecutions>- <pluginExecution>- <pluginExecutionFilter>- <groupId>org.apache.maven.plugins</groupId>- <artifactId>maven-jar-plugin</artifactId>- <versionRange>[1.0.0,]</versionRange>- <goals>- <goal>jar</goal>- </goals>- </pluginExecutionFilter>- <action>- <ignore/>- </action>- </pluginExecution>- <pluginExecution>- <pluginExecutionFilter>- <groupId>org.apache.maven.plugins</groupId>- <artifactId>maven-enforcer-plugin</artifactId>- <versionRange>[1.0.0,)</versionRange>- <goals>- <goal>enforce</goal>- </goals>- </pluginExecutionFilter>- <action>- <ignore/>- </action>- </pluginExecution>- <pluginExecution>- <pluginExecutionFilter>- <groupId>org.apache.maven.plugins</groupId>- <artifactId>maven-plugin-plugin</artifactId>- <versionRange>[1.0.0,)</versionRange>- <goals>- <goal>descriptor</goal>- </goals>- </pluginExecutionFilter>- <action>- <ignore/>- </action>- </pluginExecution>- </pluginExecutions>- </lifecycleMappingMetadata>- </configuration>- </plugin>- <plugin>- <artifactId>maven-compiler-plugin</artifactId>- <configuration>- <source>1.8</source>- <target>1.8</target>- </configuration>- </plugin>- </plugins>- </pluginManagement>- <plugins>- <plugin>- <groupId>org.apache.maven.plugins</groupId>- <artifactId>maven-enforcer-plugin</artifactId>- <version>1.3.1</version>- <executions>- <execution>- <id>enforce-java</id>- <goals>- <goal>enforce</goal>- </goals>- <configuration>- <rules>- <requireJavaVersion>- <version>1.7.0</version>- </requireJavaVersion>- </rules>- </configuration>- </execution>- </executions>- </plugin>- </plugins>- </build>- <dependencies>- <dependency>- <groupId>org.apache.maven</groupId>- <artifactId>maven-plugin-api</artifactId>- <version>${mavenVersion}</version>- </dependency>- <dependency>- <groupId>org.apache.maven</groupId>- <artifactId>maven-artifact</artifactId>- <version>${mavenVersion}</version>- </dependency>- <dependency>- <groupId>org.apache.maven</groupId>- <artifactId>maven-model</artifactId>- <version>${mavenVersion}</version>- </dependency>- <dependency>- <groupId>org.apache.maven</groupId>- <artifactId>maven-core</artifactId>- <version>${mavenVersion}</version>- </dependency>- <dependency>- <groupId>org.apache.maven</groupId>- <artifactId>maven-archiver</artifactId>- <version>2.5</version>- </dependency>- <dependency>- <groupId>org.codehaus.plexus</groupId>- <artifactId>plexus-archiver</artifactId>- <version>2.1.1</version>- </dependency>- <dependency>- <groupId>org.codehaus.plexus</groupId>- <artifactId>plexus-utils</artifactId>- <version>3.0</version>- </dependency>- <dependency>- <groupId>org.codehaus.plexus</groupId>- <artifactId>plexus-io</artifactId>- <version>2.0.4</version>- </dependency>- <dependency>- <groupId>org.apache.maven.plugins</groupId>- <artifactId>maven-antrun-plugin</artifactId>- <version>1.7</version>- <optional>true</optional>- </dependency>- </dependencies>- <distributionManagement>- <repository>- <id>pmeaseRepo</id>- <url>http://artifact.pmease.com/artifactory/pmeaseRepo</url>- </repository>- </distributionManagement>- <repositories>- <repository>- <id>pmeaseRepo</id>- <url>http://artifact.pmease.com/artifactory/pmeaseRepo</url>- <releases>- <enabled>true</enabled>- <updatePolicy>never</updatePolicy>- <checksumPolicy>fail</checksumPolicy>- </releases>- <snapshots>- <enabled>true</enabled>- <updatePolicy>always</updatePolicy>- <checksumPolicy>fail</checksumPolicy>- </snapshots>- </repository>- </repositories>- <properties>- <mavenVersion>3.2.1</mavenVersion>- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>- </properties>-</project>\ No newline at end of filediff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/CheckProjectDependenciesMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/CheckProjectDependenciesMojo.javadeleted file mode 100644index 10ac05efef..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/CheckProjectDependenciesMojo.java+++ /dev/null@@ -1,227 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.io.IOException;-import java.util.ArrayList;-import java.util.HashMap;-import java.util.HashSet;-import java.util.List;-import java.util.Map;-import java.util.Properties;-import java.util.Set;--import javax.xml.parsers.DocumentBuilder;-import javax.xml.parsers.DocumentBuilderFactory;-import javax.xml.parsers.ParserConfigurationException;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.plugin.MojoFailureException;-import org.apache.maven.project.MavenProject;-import org.codehaus.plexus.util.StringUtils;-import org.w3c.dom.Document;-import org.w3c.dom.Element;-import org.w3c.dom.NodeList;-import org.xml.sax.SAXException;--/**- * @goal check-project-dependencies- * @requiresDependencyResolution compile+runtime- */-public class CheckProjectDependenciesMojo extends AbstractMojo {-- /**- * @parameter default-value="${project}"- * @required- * @readonly- */- private MavenProject project;-- /**- * @parameter default-value="${aggregation}"- */- private boolean aggregation;-- @Override- public void execute() throws MojoExecutionException, MojoFailureException {- PluginUtils.checkResolvedArtifacts(project, true);-- Map<String, String> projectVersions = new HashMap<String, String>();-- File workspaceDir = project.getBasedir().getParentFile();- List<File> projectDirs = new ArrayList<>();- projectDirs.add(workspaceDir);- for (File file: workspaceDir.listFiles())- projectDirs.add(file);- for (File projectDir: projectDirs) {- if (!projectDir.equals(project.getBasedir())) {- File propsFile = new File(projectDir, "target/classes/"- + PluginConstants.ARTIFACT_PROPERTY_FILE);- if (propsFile.exists()) {- Properties props = PluginUtils.loadProperties(propsFile);- projectVersions.put(props.getProperty("id"), props.getProperty("version"));- } else {- File pomFile = new File(projectDir, "pom.xml");- if (pomFile.exists()) {- try {- DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();- Document document = builder.parse(pomFile);- NodeList nodeList = document.getElementsByTagName("groupId");- String groupId = null;- if (nodeList.getLength() != 0) {- groupId = nodeList.item(0).getTextContent().trim();- }-- nodeList = document.getElementsByTagName("artifactId");- if (nodeList.getLength() == 0) {- throw new MojoFailureException("Can not determine artifactId in POM '" +- pomFile.getAbsolutePath() + "'.");- }- String artifactId = nodeList.item(0).getTextContent().trim();-- nodeList = document.getElementsByTagName("version");- String version = null;- if (nodeList.getLength() != 0)- version = nodeList.item(0).getTextContent().trim();-- if (groupId == null) {- nodeList = document.getElementsByTagName("parent");- if (nodeList.getLength() == 0) {- throw new MojoFailureException("Unable to determine groupId in POM '" +- pomFile.getAbsolutePath() + "'.");- }- Element parentElement = (Element) nodeList.item(0);-- nodeList = parentElement.getElementsByTagName("groupId");- if (nodeList.getLength() == 0) {- throw new MojoFailureException("Unable to determine groupId in POM '" +- pomFile.getAbsolutePath() + "'.");- }- groupId = nodeList.item(0).getTextContent().trim();- }-- if (version == null) {- nodeList = document.getElementsByTagName("parent");- if (nodeList.getLength() == 0) {- throw new MojoFailureException("Unable to determine version in POM '" +- pomFile.getAbsolutePath() + "'.");- }- Element parentElement = (Element) nodeList.item(0);-- nodeList = parentElement.getElementsByTagName("version");- if (nodeList.getLength() == 0) {- throw new MojoFailureException("Unable to determine version in POM '" +- pomFile.getAbsolutePath() + "'.");- }- version = nodeList.item(0).getTextContent().trim();- }-- projectVersions.put(groupId + "." + artifactId, version);- } catch (ParserConfigurationException e) {- throw new MojoFailureException("Error parsing POM file '" + pomFile.getAbsolutePath() + "'.", e);- } catch (SAXException e) {- throw new MojoFailureException("Error parsing POM file '" + pomFile.getAbsolutePath() + "'.", e);- } catch (IOException e) {- throw new MojoFailureException("Error reading POM file '" + pomFile.getAbsolutePath() + "'.", e);- }- }- }- }- }-- List<String> errors = new ArrayList<String>();-- for (Artifact artifact : project.getDependencyArtifacts()) {- String projectKey = artifact.getGroupId() + "." + artifact.getArtifactId();- if (!artifact.getScope().equals(Artifact.SCOPE_TEST)) {- String projectVersion = projectVersions.get(projectKey);- if (projectVersion != null) {- if (!projectVersion.equals(artifact.getVersion())) {- errors.add("Dependency to project '" + projectKey + "' should use version '"- + projectVersion + "'");- }- }- }- }-- MavenProject parentProject = project.getParent();- if (parentProject != null) {- String projectKey = parentProject.getGroupId() + "." + parentProject.getArtifactId();- String projectVersion = projectVersions.get(projectKey);- if (projectVersion != null) {- if (!projectVersion.equals(parentProject.getVersion())) {- errors.add("Parent project '" + projectKey + "' should use version '"- + projectVersion + "'");- }- }- }-- if (aggregation) {- Set<String> dependencyKeys = new HashSet<String>();- for (Artifact artifact : project.getArtifacts()) {- if (!artifact.getScope().equals(Artifact.SCOPE_TEST))- dependencyKeys.add(artifact.getGroupId() + "." + artifact.getArtifactId());- }-- Set<String> pluginKeys = new HashSet<String>();- for (File projectDir : workspaceDir.listFiles()) {- if (!projectDir.equals(project.getBasedir())) {- File propsFile = new File(projectDir, "target/classes/"- + PluginConstants.PLUGIN_PROPERTY_FILE);- if (propsFile.exists()) {- Properties props = PluginUtils.loadProperties(propsFile);- pluginKeys.add(props.getProperty("id"));- }- }- }-- for (String pluginKey: pluginKeys) {- if (!dependencyKeys.contains(pluginKey))- errors.add("Missed dependency to project '" + pluginKey + "'.");- }-- Map<String, Set<String>> artifactVersions = new HashMap<String, Set<String>>();- for (Artifact artifact: project.getArtifacts()) {- if (PluginUtils.isRuntimeArtifact(artifact)) {- Properties props = PluginUtils.loadProperties(artifact.getFile(), PluginConstants.ARTIFACT_PROPERTY_FILE);- if (props != null) {- String dependencies = props.getProperty("dependencies");- if (dependencies != null) {- for (String dependency: PluginUtils.splitAndTrim(dependencies, ";")) {- String[] fields = StringUtils.split(dependency.trim(), ":");- Set<String> versions = artifactVersions.get(fields[0]);- if (versions == null) {- versions = new HashSet<String>();- artifactVersions.put(fields[0], versions);- }- versions.add(fields[1]);- }- }- String key = artifact.getGroupId() + "." + artifact.getArtifactId();- Set<String> versions = artifactVersions.get(key);- if (versions == null) {- versions = new HashSet<String>();- artifactVersions.put(key, versions);- }- versions.add(artifact.getVersion());- }- }- }-- for (Map.Entry<String, Set<String>> entry: artifactVersions.entrySet()) {- if (entry.getValue().size() > 1)- errors.add("Version onflicts found for dependency '" + entry.getKey() + "'.");- }- }-- if (!errors.isEmpty()) {- StringBuffer errorMessage = new StringBuffer();- for (String each : errors)- errorMessage.append(each).append(" ");- throw new MojoFailureException(errorMessage.toString());- }-- }--}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/CopyAntlrTokensMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/CopyAntlrTokensMojo.javadeleted file mode 100644index 96df5fd3f2..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/CopyAntlrTokensMojo.java+++ /dev/null@@ -1,47 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.io.IOException;--import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.plugin.MojoFailureException;-import org.apache.maven.project.MavenProject;-import org.codehaus.plexus.util.FileUtils;--/**- * @goal copy-antlr-tokens- * @requiresDependencyResolution compile+runtime- */-public class CopyAntlrTokensMojo extends AbstractMojo {-- /**- * @parameter default-value="${project}"- * @required- * @readonly- */- private MavenProject project;-- public void execute() throws MojoExecutionException, MojoFailureException {- PluginUtils.checkResolvedArtifacts(project, true);-- File outputDir = new File(project.getBuild().getOutputDirectory());-- if (!outputDir.exists())- outputDir.mkdirs();-- File antlr4Dir = new File(project.getBasedir(), "target/generated-sources/antlr4");- if (antlr4Dir.exists()) {- for (File file: antlr4Dir.listFiles()) {- if (file.getName().endsWith(".tokens")) {- try {- FileUtils.copyFileToDirectory(file, outputDir);- } catch (IOException e) {- throw new RuntimeException(e);- }- }- }- }- }--}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/CreateProductSandboxMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/CreateProductSandboxMojo.javadeleted file mode 100644index 498b4857d1..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/CreateProductSandboxMojo.java+++ /dev/null@@ -1,144 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.io.IOException;-import java.util.ArrayList;-import java.util.List;-import java.util.Properties;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.project.MavenProject;-import org.codehaus.plexus.archiver.UnArchiver;-import org.codehaus.plexus.archiver.manager.ArchiverManager;-import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;-import org.codehaus.plexus.archiver.util.ArchiveEntryUtils;-import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;-import org.codehaus.plexus.logging.Logger;-import org.codehaus.plexus.util.DirectoryScanner;-import org.codehaus.plexus.util.FileUtils;-import org.codehaus.plexus.util.StringUtils;-import org.eclipse.aether.RepositorySystem;-import org.eclipse.aether.RepositorySystemSession;-import org.eclipse.aether.repository.RemoteRepository;--import com.google.common.base.Preconditions;--/**- * @goal create-product-sandbox- * @requiresDependencyResolution compile+runtime- */-public class CreateProductSandboxMojo extends AbstractMojo {-- /**- * @parameter default-value="${project}"- * @required- * @readonly- */- private MavenProject project;-- /**- * The entry point to Aether, i.e. the component doing all the work.- *- * @component- */- private RepositorySystem repoSystem;-- /**- * @parameter default-value="${executables}"- */- private String executables;-- /**- * @parameter default-value="${moduleClass}"- */- private String moduleClass;-- /**- * The current repository/network configuration of Maven.- *- * @parameter default-value="${repositorySystemSession}"- * @readonly- */- private RepositorySystemSession repoSession;-- /**- * The project's remote repositories to use for the resolution of project dependencies.- *- * @parameter default-value="${project.remoteProjectRepositories}"- * @readonly- */- private List<RemoteRepository> remoteRepos;-- /**- * @component- */- private ArchiverManager archiverManager;-- public void execute() throws MojoExecutionException {- if (moduleClass == null || executables != null)- return;-- PluginUtils.checkResolvedArtifacts(project, true);-- for (Artifact artifact: project.getArtifacts()) {- if (PluginUtils.isRuntimeArtifact(artifact)- && PluginUtils.containsFile(artifact.getFile(), PluginConstants.PRODUCT_PROPERTY_FILE)) {- File buildDir = new File(project.getBuild().getDirectory());- File sandboxDir = new File(buildDir, PluginConstants.SANDBOX);-- File classpathFile = new File(sandboxDir, "boot/" + PluginConstants.SYSTEM_CLASSPATH);- if (!classpathFile.exists()) {- if (artifact.getFile().isFile()) {- UnArchiver unArchiver;- try {- unArchiver = archiverManager.getUnArchiver(artifact.getFile());- } catch (NoSuchArchiverException e) {- throw new RuntimeException(e);- }- unArchiver.setSourceFile(artifact.getFile());- unArchiver.setDestDirectory(buildDir);- unArchiver.setOverwrite(true);- IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] {new IncludeExcludeFileSelector()};- selectors[0].setIncludes(new String[]{PluginConstants.SANDBOX + "/**"});- unArchiver.setFileSelectors(selectors);- unArchiver.extract();- } else {- File srcDir = new File(artifact.getFile().getParentFile(), PluginConstants.SANDBOX);- try {- FileUtils.copyDirectoryStructure(srcDir, sandboxDir);- } catch (IOException e) {- throw new RuntimeException(e);- }- }-- Properties productProps = PluginUtils.loadProperties(- artifact.getFile(), PluginConstants.PRODUCT_PROPERTY_FILE);- Preconditions.checkNotNull(productProps);-- String executables = productProps.getProperty("executables");- if (executables != null && executables.trim().length() != 0) {- DirectoryScanner scanner = new DirectoryScanner();- scanner.setBasedir(sandboxDir);- List<String> includes = new ArrayList<String>();- for (String each: StringUtils.split(executables, ",")) {- if (each.trim().length() != 0)- includes.add(each.trim());- }- scanner.setIncludes(includes.toArray(new String[0]));-- scanner.scan();-- Logger logger = PluginUtils.toLogger(getLog(), "create-product-sandbox");- for (String each: scanner.getIncludedFiles())- ArchiveEntryUtils.chmod(new File(sandboxDir, each), 0755, logger);- }- PluginUtils.writeClasspath(classpathFile, project, repoSystem, repoSession, remoteRepos);- }- break;- }- }- }--}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/GenerateArtifactDescriptorMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/GenerateArtifactDescriptorMojo.javadeleted file mode 100644index 77b25d77b0..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/GenerateArtifactDescriptorMojo.java+++ /dev/null@@ -1,58 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.util.Properties;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.project.MavenProject;--/**- * @goal generate-artifact-descriptor- * @requiresDependencyResolution compile+runtime- */-public class GenerateArtifactDescriptorMojo extends AbstractMojo {-- /**- * @parameter default-value="${project}"- * @required- * @readonly- */- private MavenProject project;-- /**- * @parameter default-value="${bootstrap}"- */- private boolean bootstrap;-- public void execute() throws MojoExecutionException {- PluginUtils.checkResolvedArtifacts(project, true);-- File outputDir = new File(project.getBuild().getOutputDirectory());-- if (!outputDir.exists())- outputDir.mkdirs();-- File propsFile = new File(outputDir, PluginConstants.ARTIFACT_PROPERTY_FILE);- Properties props = new Properties();- props.put("id", project.getArtifact().getGroupId() + "." + project.getArtifact().getArtifactId());- props.put("version", project.getArtifact().getVersion());-- StringBuffer buffer = new StringBuffer();- for (Artifact artifact: project.getDependencyArtifacts()) {- if (PluginUtils.isRuntimeArtifact(artifact)- && PluginUtils.containsFile(artifact.getFile(), PluginConstants.ARTIFACT_PROPERTY_FILE)) {- buffer.append(artifact.getGroupId()).append(".").append(artifact.getArtifactId())- .append(":").append(artifact.getVersion()).append(";");- }- }- props.put("dependencies", buffer.toString());-- PluginUtils.writeProperties(propsFile, props);-- if (bootstrap)- PluginUtils.writeProperties(new File(outputDir, PluginConstants.BOOTSTRAP_PROPERTY_FILE), new Properties());- }--}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/GeneratePluginResourcesMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/GeneratePluginResourcesMojo.javadeleted file mode 100644index 3e510fc948..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/GeneratePluginResourcesMojo.java+++ /dev/null@@ -1,65 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.util.Collection;-import java.util.Properties;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.project.MavenProject;--/**- * @goal generate-plugin-resources- * @requiresDependencyResolution compile+runtime- */-public class GeneratePluginResourcesMojo extends AbstractMojo {-- /**- * @parameter default-value="${project}"- * @required- * @readonly- */- private MavenProject project;-- /**- * @parameter default-value="${moduleClass}"- */- private String moduleClass;-- public void execute() throws MojoExecutionException {- if (moduleClass == null)- return;-- PluginUtils.checkResolvedArtifacts(project, true);-- File outputDir = new File(project.getBuild().getOutputDirectory());-- if (!outputDir.exists())- outputDir.mkdirs();-- File propsFile = new File(outputDir, PluginConstants.PLUGIN_PROPERTY_FILE);- Properties props = new Properties();- props.put("name", project.getName());- if (project.getDescription() != null)- props.put("description", project.getDescription());- if (project.getOrganization() != null && project.getOrganization().getName() != null)- props.put("vendor", project.getOrganization().getName());- props.put("id", project.getArtifact().getGroupId() + "." + project.getArtifact().getArtifactId());- props.put("version", project.getArtifact().getVersion());- props.put("date", String.valueOf(System.currentTimeMillis()));- props.put("module", moduleClass);-- StringBuffer buffer = new StringBuffer();- for (Artifact artifact: ((Collection<Artifact>)project.getDependencyArtifacts())) {- if (PluginUtils.isRuntimeArtifact(artifact)- && PluginUtils.containsFile(artifact.getFile(), PluginConstants.PLUGIN_PROPERTY_FILE)) {- buffer.append(artifact.getGroupId() + "." + artifact.getArtifactId()).append(";");- }- }- props.put("dependencies", buffer.toString());-- PluginUtils.writeProperties(propsFile, props);- }--}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/GenerateProductResourcesMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/GenerateProductResourcesMojo.javadeleted file mode 100644index 1aa75d32e2..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/GenerateProductResourcesMojo.java+++ /dev/null@@ -1,85 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.util.HashSet;-import java.util.List;-import java.util.Properties;-import java.util.Set;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.project.MavenProject;-import org.eclipse.aether.RepositorySystem;-import org.eclipse.aether.RepositorySystemSession;-import org.eclipse.aether.repository.RemoteRepository;--/**- * @goal generate-product-resources- * @requiresDependencyResolution compile+runtime- */-public class GenerateProductResourcesMojo extends AbstractMojo {-- /**- * @parameter default-value="${project}"- * @required- * @readonly- */- private MavenProject project;-- /**- * @parameter default-value="${executables}"- */- private String executables;-- /**- * The entry point to Aether, i.e. the component doing all the work.- *- * @component- */- private RepositorySystem repoSystem;-- /**- * The current repository/network configuration of Maven.- *- * @parameter default-value="${repositorySystemSession}"- * @readonly- */- private RepositorySystemSession repoSession;-- /**- * The project's remote repositories to use for the resolution of project dependencies.- *- * @parameter default-value="${project.remoteProjectRepositories}"- * @readonly- */- private List<RemoteRepository> remoteRepos;-- public void execute() throws MojoExecutionException {- if (executables == null)- return;-- PluginUtils.checkResolvedArtifacts(project, true);-- File bootDir = new File(project.getBuild().getDirectory(), PluginConstants.SANDBOX + "/boot");- if (!bootDir.exists())- bootDir.mkdirs();-- Properties props = new Properties();- props.put("executables", executables);-- PluginUtils.writeProperties(- new File(project.getBuild().getOutputDirectory(), PluginConstants.PRODUCT_PROPERTY_FILE), props);-- Set<String> bootstrapKeys = new HashSet<String>();-- for (Artifact artifact: PluginUtils.getBootstrapArtifacts(project, repoSystem, repoSession, remoteRepos))- bootstrapKeys.add(PluginUtils.getArtifactKey(artifact));-- PluginUtils.writeObject(new File(bootDir, PluginConstants.BOOTSTRAP_KEYS), bootstrapKeys);-- PluginUtils.writeClasspath(new File(bootDir, PluginConstants.SYSTEM_CLASSPATH), project,- repoSystem, repoSession, remoteRepos);- }--}\ No newline at end of filediff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PackageArtifactMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PackageArtifactMojo.javadeleted file mode 100644index c79780c431..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PackageArtifactMojo.java+++ /dev/null@@ -1,175 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.io.FileOutputStream;-import java.io.IOException;-import java.util.ArrayList;-import java.util.Collection;-import java.util.HashSet;-import java.util.List;-import java.util.Set;-import java.util.jar.Attributes;-import java.util.jar.JarOutputStream;-import java.util.jar.Manifest;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.project.MavenProject;-import org.codehaus.plexus.archiver.Archiver;-import org.codehaus.plexus.archiver.manager.ArchiverManager;-import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;-import org.codehaus.plexus.util.IOUtil;-import org.eclipse.aether.RepositorySystem;-import org.eclipse.aether.RepositorySystemSession;-import org.eclipse.aether.repository.RemoteRepository;--/**- * @goal package-artifact- * @requiresDependencyResolution compile+runtime- */-public class PackageArtifactMojo extends AbstractMojo {-- /**- * @parameter default-value="${project}"- * @required- * @readonly- */- private MavenProject project;-- /**- * @component- */- private ArchiverManager archiverManager;-- /**- * The entry point to Aether, i.e. the component doing all the work.- *- * @component- */- private RepositorySystem repoSystem;-- /**- * The current repository/network configuration of Maven.- *- * @parameter default-value="${repositorySystemSession}"- * @readonly- */- private RepositorySystemSession repoSession;-- /**- * The project's remote repositories to use for the resolution of project dependencies.- *- * @parameter default-value="${project.remoteProjectRepositories}"- * @readonly- */- private List<RemoteRepository> remoteRepos;-- public void execute() throws MojoExecutionException {- PluginUtils.checkResolvedArtifacts(project, true);-- File jarFile = new File(- project.getBuild().getDirectory(),- project.getBuild().getFinalName() + ".jar");-- getLog().info("Creating jar: " + jarFile.getAbsolutePath());-- File sandboxDir = new File(project.getBuild().getDirectory(), PluginConstants.SANDBOX);-- /*- * Below code is adapted from Maven's DefaultArchetypeManager to create an archetype style- * archive to avoid the "Can not override..." warning when use this archive to generate- * an archetype.- */- JarOutputStream jos = null;- try {- Manifest manifest = new Manifest();- manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");- jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);- jos.setLevel(9);-- List<File> files = new ArrayList<File>();- PluginUtils.listFiles(new File(project.getBuild().getOutputDirectory()), files);-- boolean includeArchetypeResources = (project.getPlugin("org.apache.maven.plugins:maven-archetype-plugin")!=null);-- for (File file : files) {- PluginUtils.addFileToJar(jos, file, project.getBuild().getOutputDirectory().length(), includeArchetypeResources);- }-- if (new File(project.getBuild().getOutputDirectory(), PluginConstants.PRODUCT_PROPERTY_FILE).exists()) {- files.clear();- PluginUtils.listFiles(sandboxDir, files);-- Set<String> excluded = new HashSet<String>();- for (Artifact artifact: project.getArtifacts())- excluded.add(PluginUtils.getArtifactKey(artifact));- excluded.add(PluginConstants.SYSTEM_CLASSPATH);- excluded.add(jarFile.getName());-- for (File file: files) {- if (!excluded.contains(file.getName()))- PluginUtils.addFileToJar(jos, file, sandboxDir.getParent().length(), includeArchetypeResources);- }- }- } catch (IOException e) {- throw new RuntimeException(e);- } finally {- IOUtil.close(jos);- }-- project.getArtifact().setFile(jarFile);-- if (sandboxDir.exists()) {- PluginUtils.populateArtifacts(project, sandboxDir, archiverManager, repoSystem, repoSession, remoteRepos);-- if (!new File(project.getBuild().getOutputDirectory(), PluginConstants.PRODUCT_PROPERTY_FILE).exists()) {- Archiver archiver;- try {- archiver = archiverManager.getArchiver("zip");- } catch (NoSuchArchiverException e) {- throw new RuntimeException(e);- }-- Collection<Artifact> bootstrapArtifacts = PluginUtils.getBootstrapArtifacts(- project, repoSystem, repoSession, remoteRepos);-- Set<String> pluginTrails = new HashSet<String>();- for (Artifact artifact: project.getArtifacts()) {- if (PluginUtils.containsFile(artifact.getFile(), PluginConstants.PLUGIN_PROPERTY_FILE)) {- String trail = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"- + artifact.getType() + ":"- + (artifact.hasClassifier()?artifact.getClassifier()+":":"")- + artifact.getVersion();- pluginTrails.add(trail);- }- }-- for (Artifact artifact: project.getArtifacts()) {- if (PluginUtils.isRuntimeArtifact(artifact) && !bootstrapArtifacts.contains(artifact)) {- boolean independent = true;- for (String trail: artifact.getDependencyTrail()) {- if (pluginTrails.contains(trail)) {- independent = false;- break;- }- }- if (independent)- archiver.addFile(artifact.getFile(), PluginUtils.getArtifactKey(artifact));- }- }-- archiver.addFile(project.getArtifact().getFile(), PluginUtils.getArtifactKey(project.getArtifact()));-- File distFile = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".zip");- archiver.setDestFile(distFile);-- try {- archiver.createArchive();- } catch (Exception e) {- throw PluginUtils.unchecked(e);- }- }- }- }-}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginConstants.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginConstants.javadeleted file mode 100644index 480f9b0003..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginConstants.java+++ /dev/null@@ -1,22 +0,0 @@-package com.gitplex.plugin.maven;--public class PluginConstants {-- public static final String SYSTEM_CLASSPATH = "system.classpath";-- public static final String BOOTSTRAP_KEYS = "bootstrap.keys";-- public static final String SANDBOX = "sandbox";-- public static final String PRODUCT_PROPERTY_FILE = "META-INF/gitplex-product.properties";-- public static final String PLUGIN_PROPERTY_FILE = "META-INF/gitplex-plugin.properties";-- public static final String ARTIFACT_PROPERTY_FILE = "META-INF/gitplex-artifact.properties";-- public static final String BOOTSTRAP_PROPERTY_FILE = "META-INF/gitplex-bootstrap.properties";-- public static final String ARCHETYPE_RESOURCE = "archetype-resource/";-- public static final String ARCHETYPE_RESOURCES = "archetype-resources/";-}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginUtils.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginUtils.javadeleted file mode 100644index 7c2eb230e5..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginUtils.java+++ /dev/null@@ -1,515 +0,0 @@-package com.gitplex.plugin.maven;--import java.io.File;-import java.io.FileInputStream;-import java.io.FileOutputStream;-import java.io.IOException;-import java.io.InputStream;-import java.io.ObjectInputStream;-import java.io.ObjectOutputStream;-import java.io.OutputStream;-import java.util.ArrayList;-import java.util.Collection;-import java.util.HashMap;-import java.util.HashSet;-import java.util.List;-import java.util.Map;-import java.util.Properties;-import java.util.Set;-import java.util.jar.JarEntry;-import java.util.jar.JarFile;-import java.util.jar.JarOutputStream;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.artifact.DefaultArtifact;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.plugin.logging.Log;-import org.apache.maven.project.MavenProject;-import org.codehaus.plexus.archiver.Archiver;-import org.codehaus.plexus.archiver.manager.ArchiverManager;-import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;-import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet;-import org.codehaus.plexus.logging.Logger;-import org.codehaus.plexus.util.FileUtils;-import org.codehaus.plexus.util.IOUtil;-import org.codehaus.plexus.util.StringUtils;-import org.eclipse.aether.RepositorySystem;-import org.eclipse.aether.RepositorySystemSession;-import org.eclipse.aether.collection.CollectRequest;-import org.eclipse.aether.graph.Dependency;-import org.eclipse.aether.repository.RemoteRepository;-import org.eclipse.aether.resolution.ArtifactResult;-import org.eclipse.aether.resolution.DependencyRequest;--public class PluginUtils {-- public static boolean containsFile(File file, String path) {- if (file.isFile() && file.getName().endsWith(".jar")) {- JarFile jar = null;- try {- jar = new JarFile(file);- return jar.getJarEntry(path) != null;- } catch (Exception e) {- throw unchecked(e);- } finally {- if (jar != null) {- try {- jar.close();- } catch (IOException e) {- }- }- }- } else if (file.isDirectory() && new File(file, path).exists()) {- return true;- } else {- return false;- }- }-- public static Properties loadProperties(File file, String path) {- if (file.isFile() && file.getName().endsWith(".jar")) {- JarFile jar = null;- try {- jar = new JarFile(file);- JarEntry entry = jar.getJarEntry(path);- if (entry != null) {- InputStream is = null;- try {- is = jar.getInputStream(entry);- Properties props = new Properties();- props.load(is);- return props;- } catch (IOException e) {- throw new RuntimeException(e);- } finally {- if (is != null) {- is.close();- }- }- } else {- return null;- }- } catch (Exception e) {- throw unchecked(e);- } finally {- if (jar != null) {- try {- jar.close();- } catch (IOException e) {- }- }- }- } else if (file.isDirectory() && new File(file, path).exists()) {- Properties props = new Properties();- InputStream is = null;- try {- is = new FileInputStream(new File(file, path));- props.load(is);- return props;- } catch (IOException e) {- throw new RuntimeException(e);- } finally {- if (is != null) {- try {- is.close();- } catch (IOException e) {- }- }- }- } else {- return null;- }- }-- public static boolean isRuntimeArtifact(Artifact artifact) {- return artifact.getScope().equals(Artifact.SCOPE_COMPILE) || artifact.getScope().equals(Artifact.SCOPE_RUNTIME)- || artifact.getScope().equals(Artifact.SCOPE_SYSTEM);- }-- public static void writeClasspath(File file, MavenProject project, RepositorySystem repoSystem,- RepositorySystemSession repoSession, List<RemoteRepository> remoteRepos) throws MojoExecutionException {-- Map<String, File> classpath = new HashMap<String, File>();-- for (Artifact artifact: project.getArtifacts()) {- if (isRuntimeArtifact(artifact))- classpath.put(getArtifactKey(artifact), artifact.getFile());- }-- for (Artifact artifact: getBootstrapArtifacts(project, repoSystem, repoSession, remoteRepos))- classpath.put(getArtifactKey(artifact), artifact.getFile());-- classpath.put(getArtifactKey(project.getArtifact()), new File(project.getBuild().getOutputDirectory()));-- writeObject(file, classpath);- }-- public static Collection<Artifact> getBootstrapArtifacts(MavenProject project, RepositorySystem repoSystem,- RepositorySystemSession repoSession, List<RemoteRepository> remoteRepos) {- Collection<Artifact> bootArtifacts = new HashSet<Artifact>();- for (Artifact each: project.getArtifacts()) {- if (containsFile(each.getFile(), PluginConstants.BOOTSTRAP_PROPERTY_FILE)) {- bootArtifacts.add(each);- org.eclipse.aether.artifact.Artifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(- each.getGroupId(), each.getArtifactId(), each.getClassifier(), each.getType(),- each.getVersion());- CollectRequest collectRequest = new CollectRequest(new Dependency(aetherArtifact, null),- new ArrayList<Dependency>(), remoteRepos);- DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);- try {- for (ArtifactResult result: repoSystem.resolveDependencies(repoSession, dependencyRequest).getArtifactResults()) {- Dependency dependency = result.getRequest().getDependencyNode().getDependency();- if (dependency.getArtifact() != null && dependency.getArtifact().getFile() != null) {- aetherArtifact = dependency.getArtifact();- Artifact artifact = new DefaultArtifact(aetherArtifact.getGroupId(), aetherArtifact.getArtifactId(),- aetherArtifact.getVersion(), dependency.getScope(),- aetherArtifact.getExtension(), aetherArtifact.getClassifier(), null);- artifact.setFile(aetherArtifact.getFile());- if (isRuntimeArtifact(artifact))- bootArtifacts.add(artifact);- }- }- } catch (Exception e) {- throw PluginUtils.unchecked(e);- }- }- }- return bootArtifacts;- }-- @SuppressWarnings("unchecked")- public static void populateArtifacts(MavenProject project, File sandboxDir, ArchiverManager archiverManager,- RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository> remoteRepos) {-- if (project.getArtifact().getFile() == null)- throw new RuntimeException("Project artifact not generated yet.");-- // copy necessary library files to sandbox so that sandbox can- // be executed from command line- File bootDir = new File(sandboxDir, "boot");- File libDir = new File(sandboxDir, "lib");-- if (!bootDir.exists())- bootDir.mkdirs();- if (!libDir.exists())- libDir.mkdirs();-- Set<String> bootstrapKeys = (Set<String>) readObject(- new File(bootDir, PluginConstants.BOOTSTRAP_KEYS));-- Set<Artifact> artifacts = new HashSet<Artifact>();- for (Artifact artifact: project.getArtifacts()) {- if (isRuntimeArtifact(artifact))- artifacts.add(artifact);- }- for (Artifact artifact: getBootstrapArtifacts(project, repoSystem, repoSession, remoteRepos))- artifacts.add(artifact);- artifacts.add(project.getArtifact());-- for (Artifact artifact: artifacts) {- String artifactKey = getArtifactKey(artifact);-- File destFile;- if (bootstrapKeys.contains(artifactKey))- destFile = new File(bootDir, artifactKey);- else- destFile = new File(libDir, artifactKey);- copyArtifact(artifact.getFile(), destFile, archiverManager);- }- }-- private static void copyArtifact(File srcFile, File destFile, ArchiverManager archiverManager) {- if (containsFile(srcFile, PluginConstants.PRODUCT_PROPERTY_FILE)) {- Archiver archiver;- try {- archiver = archiverManager.getArchiver("jar");- } catch (NoSuchArchiverException e) {- throw new RuntimeException(e);- }- archiver.setDestFile(destFile);- DefaultArchivedFileSet fileSet = new DefaultArchivedFileSet();- fileSet.setArchive(srcFile);- fileSet.setExcludes(new String[]{"sandbox/**", "archetype-resources/**"});- archiver.addArchivedFileSet(fileSet);-- try {- archiver.createArchive();- } catch (Exception e) {- throw unchecked(e);- }- } else {- try {- FileUtils.copyFile(srcFile, destFile);- } catch (IOException e) {- throw new RuntimeException(e);- }- }- }-- public static Logger toLogger(final Log log, final String name) {- return new Logger() {-- @Override- public void debug(String message) {- log.debug(message);- }-- @Override- public void debug(String message, Throwable throwable) {- log.debug(message, throwable);- }-- @Override- public boolean isDebugEnabled() {- return log.isDebugEnabled();- }-- @Override- public void info(String message) {- log.info(message);- }-- @Override- public void info(String message, Throwable throwable) {- log.info(message, throwable);- }-- @Override- public boolean isInfoEnabled() {- return log.isInfoEnabled();- }-- @Override- public void warn(String message) {- log.warn(message);- }-- @Override- public void warn(String message, Throwable throwable) {- log.warn(message, throwable);- }-- @Override- public boolean isWarnEnabled() {- return log.isWarnEnabled();- }-- @Override- public void error(String message) {- log.error(message);- }-- @Override- public void error(String message, Throwable throwable) {- log.error(message, throwable);- }-- @Override- public boolean isErrorEnabled() {- return log.isErrorEnabled();- }-- @Override- public void fatalError(String message) {- log.error(message);- }-- @Override- public void fatalError(String message, Throwable throwable) {- log.error(message, throwable);- }-- @Override- public boolean isFatalErrorEnabled() {- return log.isErrorEnabled();- }-- @Override- public int getThreshold() {- return 0;- }-- @Override- public void setThreshold(int threshold) {- }-- @Override- public Logger getChildLogger(String name) {- return this;- }-- @Override- public String getName() {- return name;- }-- };- }-- public static void writeProperties(File file, Properties props) {- if (!file.getParentFile().exists())- file.getParentFile().mkdirs();- OutputStream os = null;- try {- os = new FileOutputStream(file);- props.store(os, null);- } catch (Exception e) {- throw unchecked(e);- } finally {- if (os != null) {- try {- os.close();- } catch (IOException e) {- }- }- }- }-- public static Properties loadProperties(File file) {- Properties props = new Properties();-- InputStream is = null;- try {- is = new FileInputStream(file);- props.load(is);- return props;- } catch (Exception e) {- throw unchecked(e);- } finally {- if (is != null) {- try {- is.close();- } catch (IOException e) {- }- }- }- }-- public static void writeObject(File file, Object obj) {- ObjectOutputStream oos = null;- try {- oos = new ObjectOutputStream(new FileOutputStream(file));- oos.writeObject(obj);- } catch (Exception e) {- throw unchecked(e);- } finally {- if (oos != null) {- try {- oos.close();- } catch (IOException e) {- }- }- }- }-- public static Object readObject(File file) {- ObjectInputStream ois = null;- try {- ois = new ObjectInputStream(new FileInputStream(file));- return ois.readObject();- } catch (Exception e) {- throw unchecked(e);- } finally {- if (ois != null) {- try {- ois.close();- } catch (IOException e) {- }- }- }- }-- public static RuntimeException unchecked(Throwable e) {- if (e instanceof RuntimeException)- throw (RuntimeException)e;- else- throw new RuntimeException(e);- }-- public static String getArtifactKey(Artifact artifact) {- return artifact.getGroupId() + "." + artifact.getArtifactId() + "-" + artifact.getVersion()- + (artifact.hasClassifier()? "-" + artifact.getClassifier():"") + "." + artifact.getType();- }-- public static Collection<String> splitAndTrim(String str, String separator) {- Collection<String> fields = new ArrayList<String>();- for (String each: StringUtils.split(str, separator)) {- if (each != null && each.trim().length() != 0)- fields.add(each.trim());- }- return fields;- }-- public static void checkResolvedArtifacts(MavenProject project, boolean onlyRuntime) {- for (Artifact artifact: project.getArtifacts()) {- if ((onlyRuntime && isRuntimeArtifact(artifact) || !onlyRuntime) && artifact.getFile() == null) {- throw new RuntimeException("Failed to resolve artifact '" + artifact- + "', please check if it has been relocated.");- }- }- for (Artifact artifact: project.getDependencyArtifacts()) {- if ((onlyRuntime && isRuntimeArtifact(artifact) || !onlyRuntime) && artifact.getFile() == null) {- throw new RuntimeException("Failed to resolve artifact '" + artifact- + "', please check if it has been relocated.");- }- }- }-- public static void addFileToJar(JarOutputStream jos, File file, int offset, boolean includeArchetypeResources) {- String entryName = file.getAbsolutePath().substring(offset + 1);-- if (File.separatorChar != '/')- entryName = entryName.replace('\\', '/');-- /*- * When a produt or a plugin is created via archetype "archetype.product" or "archetype.plugin",- * it will contain an archetype targeted at creating extensions to the product or plugin. To- * avoid the issue that the directory "archetype-resources/" representing the second archetype- * is trimmed when getting resources out of the archetype jar file- * by maven "DefaultArchetypeArtifactManager.getFilesetArchetypeResources" at time of generating- * the product or plugin, we rename it to "archetype-resource/"; otherwise, m2e will report- * weird errors when generating product/plugin using the archetype. Below code rename it back when- * package the archetype to confirm to maven archetype specification.- */-- if (entryName.startsWith(PluginConstants.ARCHETYPE_RESOURCE))- entryName = PluginConstants.ARCHETYPE_RESOURCES + entryName.substring(PluginConstants.ARCHETYPE_RESOURCE.length());-- if (file.isDirectory())- entryName += "/";-- if ((entryName.startsWith(PluginConstants.ARCHETYPE_RESOURCES) || entryName.equals("META-INF/maven/archetype-metadata.xml")) && !includeArchetypeResources)- return;-- try {- jos.putNextEntry(new JarEntry(entryName));- } catch (IOException e) {- throw new RuntimeException(e);- }-- if (file.isFile()) {- try {- FileInputStream is = null;- try {- is = new FileInputStream(file);- IOUtil.copy(is, jos);- } finally {- IOUtil.close(is);- }-- jos.flush();- jos.closeEntry();- } catch (IOException e) {- throw new RuntimeException(e);- }- }- }-- public static void listFiles(File dir, List<File> fileList) {- for (File file : dir.listFiles()) {- fileList.add(file);- if (file.isDirectory())- listFiles(file, fileList);- }- }-}diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/RunAntMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/RunAntMojo.javadeleted file mode 100644index 0221b6b904..0000000000--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/RunAntMojo.java+++ /dev/null@@ -1,685 +0,0 @@-package com.gitplex.plugin.maven;--/*- * Licensed to the Apache Software Foundation (ASF) under one- * or more contributor license agreements. See the NOTICE file- * distributed with this work for additional information- * regarding copyright ownership. The ASF licenses this file- * to you under the Apache License, Version 2.0 (the- * "License"); you may not use this file except in compliance- * with the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing,- * software distributed under the License is distributed on an- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY- * KIND, either express or implied. See the License for the- * specific language governing permissions and limitations- * under the License.- */--import java.io.File;-import java.io.IOException;-import java.io.LineNumberReader;-import java.io.StringWriter;-import java.util.ArrayList;-import java.util.Collection;-import java.util.Hashtable;-import java.util.Iterator;-import java.util.List;-import java.util.Properties;-import java.util.Set;--import org.apache.maven.artifact.Artifact;-import org.apache.maven.artifact.DependencyResolutionRequiredException;-import org.apache.maven.artifact.repository.ArtifactRepository;-import org.apache.maven.plugin.AbstractMojo;-import org.apache.maven.plugin.MojoExecutionException;-import org.apache.maven.plugin.antrun.AntrunXmlPlexusConfigurationWriter;-import org.apache.maven.project.MavenProject;-import org.apache.maven.project.MavenProjectHelper;-import org.apache.tools.ant.BuildException;-import org.apache.tools.ant.DefaultLogger;-import org.apache.tools.ant.Project;-import org.apache.tools.ant.ProjectHelper;-import org.apache.tools.ant.taskdefs.Typedef;-import org.apache.tools.ant.types.Path;-import org.codehaus.plexus.configuration.PlexusConfiguration;-import org.codehaus.plexus.configuration.PlexusConfigurationException;-import org.codehaus.plexus.util.FileUtils;-import org.codehaus.plexus.util.IOUtil;-import org.codehaus.plexus.util.ReaderFactory;-import org.codehaus.plexus.util.StringUtils;--/**- * This task does the same as maven-antrun-plugin's run goal except that it will be executed upon- * Eclipse incremental build (via m2e lifecycle mapping in com.gitplex.maven.parent pom). If you- * want to execute ant tasks without being invoked by Eclipse incremental build, please use- * maven-antrun-plugin's run goal instead.- *- * @goal run-ant- * @threadSafe- * @requiresDependencyResolution test- */-public class RunAntMojo extends AbstractMojo-{- /**- * The refid used to store the Maven project object in the Ant build.- */- public final static String DEFAULT_MAVEN_PROJECT_REFID = "maven.project";-- /**- * The refid used to store the Maven project object in the Ant build.- */- public final static String DEFAULT_MAVEN_PROJECT_HELPER_REFID = "maven.project.helper";-- /**- * The default target name.- */- public final static String DEFAULT_ANT_TARGET_NAME = "main";-- /**- * The default encoding to use for the generated Ant build.- */- public final static String UTF_8 = "UTF-8";-- /**- * The name used for the ant target- */- private String antTargetName;-- /**- * The path to The XML file containing the definition of the Maven tasks.- */- public final static String ANTLIB = "org/apache/maven/ant/tasks/antlib.xml";-- /**- * The URI which defines the built in Ant tasks- */- public final static String TASK_URI = "antlib:org.apache.maven.ant.tasks";-- /**- * The Maven project object- *- * @parameter expression="${project}"- * @readonly- */- private MavenProject project;-- /**- * The Maven project helper object- *- * @component- */- private MavenProjectHelper projectHelper;-- /**- * The plugin dependencies.- *- * @parameter expression="${plugin.artifacts}"- * @required- * @readonly- */- @SuppressWarnings("rawtypes")- private List pluginArtifacts;-- /**- * The local Maven repository- *- * @parameter expression="${localRepository}"- * @readonly- */- protected ArtifactRepository localRepository;-- /**- * String to prepend to project and dependency property names.- *- * @parameter default-value=""- * @since 1.4- */- private String propertyPrefix;-- /**- * The xml tag prefix to use for the built in Ant tasks. This prefix needs to be prepended to each task referenced- * in the antrun target config. For example, a prefix of "mvn" means that the attachartifact task is referenced by- * "<mvn:attachartifact>" The default value of an empty string means that no prefix is used for the tasks.- *- * @parameter default-value=""- * @since 1.5- */- private String customTaskPrefix = "";-- /**- * The name of a property containing the list of all dependency versions. This is used for the removing the versions- * from the filenames.- *- * @parameter default-value="maven.project.dependencies.versions"- */- private String versionsPropertyName;-- /**- * The XML for the Ant task. You can add anything you can add between <target> and </target> in a- * build.xml.- *- * @deprecated Use target instead- * @parameter- */- private PlexusConfiguration tasks;-- /**- * The XML for the Ant target. You can add anything you can add between <target> and </target> in a- * build.xml.- *- * @parameter- * @since 1.5- */- private PlexusConfiguration target;-- /**- * This folder is added to the list of those folders containing source to be compiled. Use this if your ant script- * generates source code.- *- * @parameter expression="${sourceRoot}"- * @deprecated Use the build-helper-maven-plugin to bind source directories- */- private File sourceRoot;-- /**- * This folder is added to the list of those folders containing source to be compiled for testing. Use this if your- * ant script generates test source code.- *- * @parameter expression="${testSourceRoot}"- * @deprecated Use the build-helper-maven-plugin to bind test source directories- */- private File testSourceRoot;-- /**- * Specifies whether the Antrun execution should be skipped.- *- * @parameter expression="${maven.antrun.skip}" default-value="false"- * @since 1.7- */- private boolean skip;-- /**- * Specifies whether the Ant properties should be propagated to the Maven properties.- *- * @parameter default-value="false"- * @since 1.7- */- private boolean exportAntProperties;-- /**- * Specifies whether a failure in the ant build leads to a failure of the Maven build.- *- * If this value is 'true', the Maven build will proceed even if the ant build fails.- * If it is 'false', then the Maven build fails if the ant build fails.- *- * @parameter default-value="true"- * @since 1.7- */- private boolean failOnError;-- /**- * @see org.apache.maven.plugin.Mojo#execute()- */- public void execute()- throws MojoExecutionException- {- PluginUtils.checkResolvedArtifacts(project, false);-- if ( skip )- {- getLog().info( "Skipping Antrun execution" );- return;- }-- MavenProject mavenProject = getMavenProject();-- if ( tasks != null )- {- getLog().warn( "Parameter tasks is deprecated, use target instead" );- target = tasks;- }-- if ( target == null )- {- getLog().info( "No ant target defined - SKIPPED" );- return;- }-- if ( propertyPrefix == null )- {- propertyPrefix = "";- }-- try- {- Project antProject = new Project();- File antBuildFile = this.writeTargetToProjectFile( );- ProjectHelper.configureProject( antProject, antBuildFile );- antProject.init();-- DefaultLogger antLogger = new DefaultLogger();- antLogger.setOutputPrintStream( System.out );- antLogger.setErrorPrintStream( System.err );-- if ( getLog().isDebugEnabled() )- {- antLogger.setMessageOutputLevel( Project.MSG_DEBUG );- }- else if ( getLog().isInfoEnabled() )- {- antLogger.setMessageOutputLevel( Project.MSG_INFO );- }- else if ( getLog().isWarnEnabled() )- {- antLogger.setMessageOutputLevel( Project.MSG_WARN );- }- else if ( getLog().isErrorEnabled() )- {- antLogger.setMessageOutputLevel( Project.MSG_ERR );- }- else- {- antLogger.setMessageOutputLevel( Project.MSG_VERBOSE );- }-- antProject.addBuildListener( antLogger );- antProject.setBaseDir( mavenProject.getBasedir() );-- Path p = new Path( antProject );- p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) );-- /* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */- antProject.addReference( "maven.dependency.classpath", p );- antProject.addReference( "maven.compile.classpath", p );-- p = new Path( antProject );- p.setPath( StringUtils.join( mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator ) );- antProject.addReference( "maven.runtime.classpath", p );-- p = new Path( antProject );- p.setPath( StringUtils.join( mavenProject.getTestClasspathElements().iterator(), File.pathSeparator ) );- antProject.addReference( "maven.test.classpath", p );-- /* set maven.plugin.classpath with plugin dependencies */- antProject.addReference( "maven.plugin.classpath", getPathFromArtifacts( pluginArtifacts, antProject ) );-- antProject.addReference( DEFAULT_MAVEN_PROJECT_REFID, getMavenProject() );- antProject.addReference( DEFAULT_MAVEN_PROJECT_HELPER_REFID, projectHelper );- antProject.addReference( "maven.local.repository", localRepository );- initMavenTasks( antProject );-- // The ant project needs actual properties vs. using expression evaluator when calling an external build- // file.- copyProperties( mavenProject, antProject );-- if ( getLog().isInfoEnabled() )- {- getLog().info( "Executing tasks" );- }-- antProject.executeTarget( antTargetName );-- if ( getLog().isInfoEnabled() )- {- getLog().info( "Executed tasks" );- }-- copyProperties( antProject, mavenProject );- }- catch ( DependencyResolutionRequiredException e )- {- throw new MojoExecutionException( "DependencyResolutionRequiredException: " + e.getMessage(), e );- }- catch ( BuildException e )- {- StringBuffer sb = new StringBuffer();- sb.append( "An Ant BuildException has occured: " + e.getMessage() );- String fragment = findFragment( e );- if ( fragment != null )- {- sb.append( "\n" ).append( fragment );- }- if ( !failOnError )- {- getLog().info( sb.toString(), e );- return; // do not register roots.- } else- {- throw new MojoExecutionException( sb.toString(), e );- }- }- catch ( Throwable e )- {- throw new MojoExecutionException( "Error executing ant tasks: " + e.getMessage(), e );- }-- if ( sourceRoot != null )- {- getLog().info( "Registering compile source root " + sourceRoot );- getMavenProject().addCompileSourceRoot( sourceRoot.toString() );- }-- if ( testSourceRoot != null )- {- getLog().info( "Registering compile test source root " + testSourceRoot );- getMavenProject().addTestCompileSourceRoot( testSourceRoot.toString() );- }- }-- /**- * @param artifacts- * @param antProject- * @return a path- * @throws DependencyResolutionRequiredException- */- @SuppressWarnings({ "rawtypes", "unchecked" })- public Path getPathFromArtifacts( Collection artifacts, Project antProject )- throws DependencyResolutionRequiredException- {- if ( artifacts == null )- {- return new Path( antProject );- }-- List list = new ArrayList( artifacts.size() );- for ( Iterator i = artifacts.iterator(); i.hasNext(); )- {- Artifact a = (Artifact) i.next();- File file = a.getFile();- if ( file == null )- {- throw new DependencyResolutionRequiredException( a );- }- list.add( file.getPath() );- }-- Path p = new Path( antProject );- p.setPath( StringUtils.join( list.iterator(), File.pathSeparator ) );-- return p;- }-- /**- * Copy properties from the maven project to the ant project.- *- * @param mavenProject- * @param antProject- */- @SuppressWarnings("rawtypes")- public void copyProperties( MavenProject mavenProject, Project antProject )- {- Properties mavenProps = mavenProject.getProperties();- Iterator iter = mavenProps.keySet().iterator();- while ( iter.hasNext() )- {- String key = (String) iter.next();- antProject.setProperty( key, mavenProps.getProperty( key ) );- }-- // Set the POM file as the ant.file for the tasks run directly in Maven.- antProject.setProperty( "ant.file", mavenProject.getFile().getAbsolutePath() );-- // Add some of the common maven properties- getLog().debug("Setting properties with prefix: " + propertyPrefix );- antProject.setProperty( ( propertyPrefix + "project.groupId" ), mavenProject.getGroupId() );- antProject.setProperty( ( propertyPrefix + "project.artifactId" ), mavenProject.getArtifactId() );- antProject.setProperty( ( propertyPrefix + "project.name" ), mavenProject.getName() );- if ( mavenProject.getDescription() != null)- {- antProject.setProperty( ( propertyPrefix + "project.description" ), mavenProject.getDescription() );- }- antProject.setProperty( ( propertyPrefix + "project.version" ), mavenProject.getVersion() );- antProject.setProperty( ( propertyPrefix + "project.packaging" ), mavenProject.getPackaging() );- antProject.setProperty( ( propertyPrefix + "project.build.directory" ), mavenProject.getBuild().getDirectory() );- antProject.setProperty( ( propertyPrefix + "project.build.outputDirectory" ),- mavenProject.getBuild().getOutputDirectory() );- antProject.setProperty( ( propertyPrefix + "project.build.testOutputDirectory" ),- mavenProject.getBuild().getTestOutputDirectory() );- antProject.setProperty( ( propertyPrefix + "project.build.sourceDirectory" ),- mavenProject.getBuild().getSourceDirectory() );- antProject.setProperty( ( propertyPrefix + "project.build.testSourceDirectory" ),- mavenProject.getBuild().getTestSourceDirectory() );- antProject.setProperty( ( propertyPrefix + "localRepository" ), localRepository.toString() );- antProject.setProperty( ( propertyPrefix + "settings.localRepository" ), localRepository.getBasedir() );-- // Add properties for depenedency artifacts- Set depArtifacts = mavenProject.getArtifacts();- for ( Iterator it = depArtifacts.iterator(); it.hasNext(); )- {- Artifact artifact = (Artifact) it.next();-- String propName = artifact.getDependencyConflictId();-- antProject.setProperty( propertyPrefix + propName, artifact.getFile().getPath() );- }-- // Add a property containing the list of versions for the mapper- StringBuffer versionsBuffer = new StringBuffer();- for ( Iterator it = depArtifacts.iterator(); it.hasNext(); )- {- Artifact artifact = (Artifact) it.next();-- versionsBuffer.append( artifact.getVersion() + File.pathSeparator );- }- antProject.setProperty( versionsPropertyName, versionsBuffer.toString() );-- // Add properties in deprecated format to depenedency artifacts- // This should be removed in future versions of the antrun plugin.- for ( Iterator it = depArtifacts.iterator(); it.hasNext(); )- {- Artifact artifact = (Artifact) it.next();-- String propName = getDependencyArtifactPropertyName( artifact );-- antProject.setProperty( propName, artifact.getFile().getPath() );- }- }-- /**- * Copy properties from the ant project to the maven project.- *- * @param antProject not null- * @param mavenProject not null- * @since 1.7- */- @SuppressWarnings("rawtypes")- public void copyProperties( Project antProject, MavenProject mavenProject )- {- if ( !exportAntProperties )- {- return;- }-- getLog().debug( "Propagated Ant properties to Maven properties" );- Hashtable antProps = antProject.getProperties();-- Iterator iter = antProps.keySet().iterator();- while ( iter.hasNext() )- {- String key = (String) iter.next();-- Properties mavenProperties = mavenProject.getProperties();- if ( mavenProperties.getProperty( key ) != null )- {- getLog().debug( "Ant property '" + key +"=" +mavenProperties.getProperty( key )- + "' clashs with an existing Maven property, SKIPPING this Ant property propagation." );- continue;- }- mavenProperties.setProperty( key, antProps.get( key ).toString() );- }- }-- /**- * Prefix for legacy property format.- * @deprecated This should only be used for generating the old property format.- */- public static final String DEPENDENCY_PREFIX = "maven.dependency.";-- /**- * Returns a property name for a dependency artifact. The name is in the format- * maven.dependency.groupId.artifactId[.classifier].type.path- *- * @param artifact- * @return property name- * @deprecated The dependency conflict ID should be used as the property name.- */- public static String getDependencyArtifactPropertyName( Artifact artifact )- {- String key = DEPENDENCY_PREFIX + artifact.getGroupId() + "." + artifact.getArtifactId()- + ( artifact.getClassifier() != null ? "." + artifact.getClassifier() : "" )- + ( artifact.getType() != null ? "." + artifact.getType() : "" ) + ".path";- return key;- }-- /**- * Get the current Maven project- *- * @return current Maven project- */- public MavenProject getMavenProject()- {- return this.project;- }-- public void initMavenTasks( Project antProject )- {- getLog().debug( "Initialize Maven Ant Tasks" );- Typedef typedef = new Typedef();- typedef.setProject( antProject );- typedef.setResource( ANTLIB );- if ( ! customTaskPrefix.equals( "" ) )- {- typedef.setURI( TASK_URI );- }- typedef.execute();- }-- /**- * Write the ant target and surrounding tags to a temporary file- *- * @throws PlexusConfigurationException- */- private File writeTargetToProjectFile()- throws IOException, PlexusConfigurationException- {- // Have to use an XML writer because in Maven 2.x the PlexusConfig toString() method loses XML attributes- StringWriter writer = new StringWriter();- AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();- xmlWriter.write( target, writer );-- StringBuffer antProjectConfig = writer.getBuffer();-- // replace deprecated tasks tag with standard Ant target- stringReplace( antProjectConfig, "<tasks", "<target" );- stringReplace( antProjectConfig, "</tasks", "</target" );-- antTargetName = target.getAttribute( "name" );-- if ( antTargetName == null )- {- antTargetName = DEFAULT_ANT_TARGET_NAME;- stringReplace( antProjectConfig, "<target", "<target name=\"" + antTargetName + "\"" );- }-- String xmlns = "";- if ( ! customTaskPrefix.trim().equals( "" ) )- {- xmlns = "xmlns:" + customTaskPrefix + "=\"" + TASK_URI + "\"";- }-- final String xmlHeader = "<?xml version=\"1.0\" encoding=\"" + UTF_8 + "\" ?>\n";- antProjectConfig.insert( 0, xmlHeader );- final String projectOpen = "<project name=\"maven-antrun-\" default=\"" + antTargetName + "\" " + xmlns +" >\n";- int index = antProjectConfig.indexOf( "<target" );- antProjectConfig.insert( index, projectOpen );-- final String projectClose = "\n</project>";- antProjectConfig.append( projectClose );-- // The fileName should probably use the plugin executionId instead of the targetName- String fileName = "build-" + antTargetName + ".xml";- File buildFile = new File( project.getBuild().getDirectory(), "/antrun/" + fileName );-- buildFile.getParentFile().mkdirs();- FileUtils.fileWrite( buildFile.getAbsolutePath(), UTF_8, antProjectConfig.toString() );- return buildFile;- }-- /**- * Replace text in a StringBuffer. If the match text is not found, the StringBuffer- * is returned unchanged.- *- * @param text The string buffer containing the text- * @param match The string to match and remove- * @param with The string to insert- */- public void stringReplace( StringBuffer text, String match, String with )- {- int index = text.indexOf( match );- if ( index != -1 )- {- text.replace( index, index + match.length(), with );- }- }-- public String checkTargetName( PlexusConfiguration antTargetConfig )- throws PlexusConfigurationException- {- String targetName = antTargetConfig.getAttribute( "name" );- if ( targetName == null )- {- targetName = DEFAULT_ANT_TARGET_NAME;- }- return targetName;- }-- /**- * @param buildException not null- * @return the fragment XML part where the buildException occurs.- * @since 1.7- */- private String findFragment( BuildException buildException )- {- if ( buildException == null || buildException.getLocation() == null- || buildException.getLocation().getFileName() == null )- {- return null;- }-- File antFile = new File( buildException.getLocation().getFileName() );- if ( !antFile.exists() )- {- return null;- }-- LineNumberReader reader = null;- try- {- reader = new LineNumberReader( ReaderFactory.newXmlReader( antFile ) );- String line = "";- while ( ( line = reader.readLine() ) != null )- {- if ( reader.getLineNumber() == buildException.getLocation().getLineNumber() )- {- return "around Ant part ..." + line.trim() + "... @ " + buildException.getLocation().getLineNumber() + ":"- + buildException.getLocation().getColumnNumber() + " in " + antFile.getAbsolutePath();- }- }- }- catch ( Exception e )- {- getLog().debug( e.getMessage(), e );- return null;- }- finally- {- IOUtil.close( reader );- }-- return null;- }-}diff --git a/pom.xml b/pom.xmlindex aaaa059449..240f31b387 100644--- a/pom.xml+++ b/pom.xml@@ -34,7 +34,6 @@<module>archetype.artifact</module><module>archetype.plugin</module><module>archetype.product</module>- <module>plugin.maven</module></modules><build><finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>