Search in sources :

Example 1 with PomPropertiesUtil

use of org.apache.maven.archiver.PomPropertiesUtil in project aries by apache.

the class EsaMojo method addMavenDescriptor.

private void addMavenDescriptor() throws MojoExecutionException {
    try {
        if (addMavenDescriptor) {
            if (project.getArtifact().isSnapshot()) {
                project.setVersion(project.getArtifact().getVersion());
            }
            String groupId = project.getGroupId();
            String artifactId = project.getArtifactId();
            zipArchiver.addFile(project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
            PomPropertiesUtil pomPropertiesUtil = new PomPropertiesUtil();
            File dir = new File(project.getBuild().getDirectory(), "maven-zip-plugin");
            File pomPropertiesFile = new File(dir, "pom.properties");
            pomPropertiesUtil.createPomProperties(project, zipArchiver, pomPropertiesFile, forceCreation);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling esa", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) PomPropertiesUtil(org.apache.maven.archiver.PomPropertiesUtil) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException)

Example 2 with PomPropertiesUtil

use of org.apache.maven.archiver.PomPropertiesUtil in project aries by apache.

the class EbaMojo method execute.

public void execute() throws MojoExecutionException {
    getLog().debug(" ======= EbaMojo settings =======");
    getLog().debug("ebaSourceDirectory[" + ebaSourceDirectory + "]");
    getLog().debug("manifestFile[" + manifestFile + "]");
    getLog().debug("applicationManifestFile[" + applicationManifestFile + "]");
    getLog().debug("workDirectory[" + workDirectory + "]");
    getLog().debug("outputDirectory[" + outputDirectory + "]");
    getLog().debug("finalName[" + finalName + "]");
    getLog().debug("generateManifest[" + generateManifest + "]");
    if (archiveContent == null) {
        archiveContent = new String("applicationContent");
    }
    getLog().debug("archiveContent[" + archiveContent + "]");
    getLog().info("archiveContent[" + archiveContent + "]");
    zipArchiver.setIncludeEmptyDirs(includeEmptyDirs);
    zipArchiver.setCompress(true);
    zipArchiver.setForced(forceCreation);
    // Check if jar file is there and if requested, copy it
    try {
        if (includeJar.booleanValue()) {
            File generatedJarFile = new File(outputDirectory, finalName + ".jar");
            if (generatedJarFile.exists()) {
                getLog().info("Including generated jar file[" + generatedJarFile.getName() + "]");
                zipArchiver.addFile(generatedJarFile, finalName + ".jar");
            }
        }
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error adding generated Jar file", e);
    }
    // Copy dependencies
    try {
        Set<Artifact> artifacts = null;
        if (useTransitiveDependencies || "all".equals(archiveContent)) {
            // to the same compatible value or is the default).
            if ("none".equals(archiveContent)) {
                throw new MojoExecutionException("<useTransitiveDependencies/> and <archiveContent/> incompatibly configured.  <useTransitiveDependencies/> is deprecated in favor of <archiveContent/>.");
            } else {
                artifacts = project.getArtifacts();
            }
        } else {
            // check that archiveContent is compatible
            if ("applicationContent".equals(archiveContent)) {
                artifacts = project.getDependencyArtifacts();
            } else {
                // the only remaining options should be applicationContent="none"
                getLog().info("archiveContent=none: application arvhive will not contain any bundles.");
            }
        }
        if (artifacts != null) {
            for (Artifact artifact : artifacts) {
                ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
                if (!artifact.isOptional() && filter.include(artifact)) {
                    getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
                    zipArchiver.addFile(artifact.getFile(), artifact.getArtifactId() + "-" + artifact.getVersion() + "." + (artifact.getType() == null ? "jar" : artifact.getType()));
                }
            }
        }
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error copying EBA dependencies", e);
    }
    // Copy source files
    try {
        File ebaSourceDir = ebaSourceDirectory;
        if (ebaSourceDir.exists()) {
            getLog().info("Copy eba resources to " + getBuildDir().getAbsolutePath());
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(ebaSourceDir.getAbsolutePath());
            scanner.setIncludes(DEFAULT_INCLUDES);
            scanner.addDefaultExcludes();
            scanner.scan();
            String[] dirs = scanner.getIncludedDirectories();
            for (int j = 0; j < dirs.length; j++) {
                new File(getBuildDir(), dirs[j]).mkdirs();
            }
            String[] files = scanner.getIncludedFiles();
            for (int j = 0; j < files.length; j++) {
                File targetFile = new File(getBuildDir(), files[j]);
                targetFile.getParentFile().mkdirs();
                File file = new File(ebaSourceDir, files[j]);
                FileUtils.copyFileToDirectory(file, targetFile.getParentFile());
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error copying EBA resources", e);
    }
    // Include custom manifest if necessary
    try {
        if (!generateManifest) {
            includeCustomApplicationManifestFile();
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying APPLICATION.MF file", e);
    }
    // Generate application manifest if requested
    if (generateManifest) {
        String fileName = new String(getBuildDir() + "/" + APPLICATION_MF_URI);
        File appMfFile = new File(fileName);
        try {
            // Delete any old manifest
            if (appMfFile.exists()) {
                FileUtils.fileDelete(fileName);
            }
            appMfFile.getParentFile().mkdirs();
            if (appMfFile.createNewFile()) {
                writeApplicationManifest(fileName);
            }
        } catch (java.io.IOException e) {
            throw new MojoExecutionException("Error generating APPLICATION.MF file: " + fileName, e);
        }
    }
    // Check if connector deployment descriptor is there
    File ddFile = new File(getBuildDir(), APPLICATION_MF_URI);
    if (!ddFile.exists()) {
        getLog().warn("Application manifest: " + ddFile.getAbsolutePath() + " does not exist.");
    }
    try {
        if (addMavenDescriptor) {
            if (project.getArtifact().isSnapshot()) {
                project.setVersion(project.getArtifact().getVersion());
            }
            String groupId = project.getGroupId();
            String artifactId = project.getArtifactId();
            zipArchiver.addFile(project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
            PomPropertiesUtil pomPropertiesUtil = new PomPropertiesUtil();
            File dir = new File(project.getBuild().getDirectory(), "maven-zip-plugin");
            File pomPropertiesFile = new File(dir, "pom.properties");
            pomPropertiesUtil.createPomProperties(project, zipArchiver, pomPropertiesFile, forceCreation);
        }
        File ebaFile = new File(outputDirectory, finalName + ".eba");
        zipArchiver.setDestFile(ebaFile);
        File buildDir = getBuildDir();
        if (buildDir.isDirectory()) {
            zipArchiver.addDirectory(buildDir);
        }
        // include legal files if any
        File sharedResourcesDir = new File(sharedResources);
        if (sharedResourcesDir.isDirectory()) {
            zipArchiver.addDirectory(sharedResourcesDir);
        }
        zipArchiver.createArchive();
        project.getArtifact().setFile(ebaFile);
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling eba", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) File(java.io.File) PomPropertiesUtil(org.apache.maven.archiver.PomPropertiesUtil)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 PomPropertiesUtil (org.apache.maven.archiver.PomPropertiesUtil)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2 Artifact (org.apache.maven.artifact.Artifact)1 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)1 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)1