Example usage for org.apache.maven.plugin.logging Log isDebugEnabled

List of usage examples for org.apache.maven.plugin.logging Log isDebugEnabled

Introduction

In this page you can find the example usage for org.apache.maven.plugin.logging Log isDebugEnabled.

Prototype

boolean isDebugEnabled();

Source Link

Usage

From source file:org.apache.james.mailet.DefaultDescriptorsExtractor.java

License:Apache License

private void logDirectories(MavenProject project, Log log) {
    if (log.isDebugEnabled()) {
        log.debug("OutDir: " + project.getBuild().getOutputDirectory());
    }/*from   w  ww . ja  v  a2s  .co m*/
}

From source file:org.apache.james.mailet.DefaultDescriptorsExtractor.java

License:Apache License

private void logProjectDependencies(MavenProject project, Log log) {
    log.debug("Logging project dependencies");
    if (log.isDebugEnabled()) {
        @SuppressWarnings("unchecked")
        final Set<Artifact> dependencies = project.getDependencyArtifacts();
        if (dependencies == null) {
            log.debug("No project dependencies");
        } else {//from   ww  w .j  a va2  s  .c o m
            for (Artifact artifact : dependencies) {
                log.debug("DEP: " + artifact);
            }
        }
    }
}

From source file:org.apache.pluto.maven.AssembleMojo.java

License:Apache License

protected void doValidate() throws MojoExecutionException {
    Log log = getLog();

    // Support for the old 'warFiles' mojo parameter.  Apparently
    // the alias for the 'archives' parameter doesn't work properly.
    if (!(warFiles == null || warFiles.isEmpty())) {
        log.warn("'warFiles' parameter is deprecated.  Use 'archives' parameter instead.");
        if (archives == null) {
            archives = new ArrayList();
        }//from w w  w . ja v a2 s  .co m
        archives.addAll(warFiles);
    }

    // Warn if the old 'warFilesDestination' mojo parameter is used
    if (warFilesDestination != null) {
        log.warn("'warFilesDestination' parameter is deprecated.  Use 'assemblyOutputDirectory' instead.");
        assemblyOutputDirectory = warFilesDestination;
    }

    // If a list of war files are supplied:
    //   1) webXml, portletXml, and webXmlDestination parameters are ignored
    //   2) verify the files in the List exist.
    //   3) verify the destination is a directory, or create it if it doesn't exist.

    // A list of files was supplied so we ignore other parameters. 
    if (archives != null && !archives.isEmpty()) {
        if (webXml != null) {
            log.debug(
                    "archives parameter and webXml parameter are mutually exclusive.  Ignoring webXml parameter.");
        }
        if (portletXml != null) {
            log.debug(
                    "archives parameter and portletXml parameter are mutually exclusive.  Ignoring portletXml parameter.");
        }
        if (webXmlDestination != null) {
            log.debug(
                    "archives parameter and webXmlDestination parameter are mutually exclusive.  Ignoring webXmlDestination parameter.");
        }

        // verify each file can be found
        for (Iterator i = archives.iterator(); i.hasNext();) {
            File f = new File(i.next().toString());
            if (!f.exists()) {
                log.warn("File " + f.getAbsolutePath() + " does not exist.");
                i.remove();
                continue;
            }
            if (!f.canRead()) {
                log.warn("File " + f.getAbsolutePath() + " exists but cannot be read.");
                i.remove();
                continue;
            }
        }

        // check to see if the warFiles list is now empty
        if (archives.isEmpty()) {
            throw new MojoExecutionException("No war files could be installed due errors.");
        }

        // check to see if the dest dir exists or create it.
        if (!assemblyOutputDirectory.exists()) {
            if (log.isDebugEnabled()) {
                log.debug("Creating destination directory for assembled war files: "
                        + assemblyOutputDirectory.getAbsolutePath());
            }
            try {
                if (!assemblyOutputDirectory.mkdirs()) {
                    throw new MojoExecutionException(
                            "Unable to create destination directory for assembled war files: "
                                    + assemblyOutputDirectory.getAbsolutePath());
                }
            } catch (SecurityException e) {
                throw new MojoExecutionException(
                        "Unable to create destination directory for assembled war files: " + e.getMessage(), e);
            }
        } else {
            if (!assemblyOutputDirectory.isDirectory()) {
                throw new MojoExecutionException("Specified destination for assembled war files "
                        + assemblyOutputDirectory.getAbsolutePath() + " is not a directory!");
            }
            if (!assemblyOutputDirectory.canRead() || !assemblyOutputDirectory.canWrite()) {
                throw new MojoExecutionException(
                        "Unable to read or write to destination directory for assembed war files.  "
                                + "Check permissions on the directory "
                                + assemblyOutputDirectory.getAbsolutePath());
            }
        }

        // A list of archive files was not provided, so use the other parameters instead.

    } else {
        if (webXml == null || !webXml.exists()) {
            throw new MojoExecutionException("Web application descriptor must be a valid web.xml");
        }
        if (portletXml == null || !portletXml.exists()) {
            throw new MojoExecutionException("Portlet descriptor must be a valid portlet.xml");
        }
    }
}

From source file:org.apache.tuscany.maven.bundle.plugin.BundlesMetaDataBuildMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    Log log = getLog();

    Set<Artifact> artifacts = null;
    if (includeConflictingDepedencies) {
        try {// w ww.ja v a 2 s. c o  m
            artifacts = getDependencyArtifacts(project);
        } catch (Exception e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    } else {
        artifacts = project.getArtifacts();
    }

    try {

        // Create the target directory
        File root;
        if (targetDirectory == null) {
            root = new File(project.getBuild().getDirectory(), "plugins/");
        } else {
            root = targetDirectory;
        }

        if (generateModules) {
            root.mkdirs();
        }

        // Build sets of exclude directories and included/excluded/groupids
        Set<String> excludedFileNames = new HashSet<String>();
        if (excludeDirectories != null) {
            for (File f : excludeDirectories) {
                if (f.isDirectory()) {
                    for (String n : f.list()) {
                        excludedFileNames.add(n);
                    }
                }
            }
        }
        Set<String> includedGroupIds = new HashSet<String>();
        if (includeGroupIds != null) {
            for (String g : includeGroupIds) {
                includedGroupIds.add(g);
            }
        }
        Set<String> excludedGroupIds = new HashSet<String>();
        if (excludeGroupIds != null) {
            for (String g : excludeGroupIds) {
                excludedGroupIds.add(g);
            }
        }

        // Find all the distribution poms
        List<MavenProject> poms = new ArrayList<MavenProject>();

        if (useDistributionName) {
            for (Object o : project.getArtifacts()) {
                Artifact artifact = (Artifact) o;
                if ("pom".equals(artifact.getType()) && artifact.getGroupId().equals(project.getGroupId())
                        && artifact.getArtifactId().startsWith("tuscany-feature-")) {
                    log.info("Dependent distribution: " + artifact);
                    MavenProject pomProject = buildProject(artifact);
                    poms.add(pomProject);
                    // log.info(pomProject.getArtifactMap().toString());
                }
            }
        }

        if (features != null) {
            // find all the features that require processing
            for (Object o : project.getArtifacts()) {
                Artifact artifact = (Artifact) o;
                for (Feature feature : features) {
                    if (artifact.getGroupId().equals(feature.getGroupId())
                            && artifact.getArtifactId().equals(feature.getArtifactId())) {
                        log.info("Feature: " + artifact);
                        MavenProject pomProject = buildProject(artifact);
                        poms.add(pomProject);
                    }
                }
            }

            // force useDistributionName to true so that subsequent generation works
            useDistributionName = true;
        }

        if (extensions != null) {
            // find all the extensions that require processing
            // TODO - putting them in features dir for the time being
            for (Object o : project.getArtifacts()) {
                Artifact artifact = (Artifact) o;
                for (Extension extension : extensions) {
                    if (artifact.getGroupId().equals(extension.getGroupId())
                            && artifact.getArtifactId().equals(extension.getArtifactId())) {
                        log.info("Extension: " + artifact);
                        MavenProject pomProject = buildProject(artifact);
                        poms.add(pomProject);
                    }
                }
            }

            // force useDistributionName to true so that subsequent generation works
            useDistributionName = true;
        }

        // If no features have been specified assume that the current
        // project defines the feature
        if (poms.size() == 0) {
            poms.add(project);
        }

        // Process all the dependency artifacts
        ProjectSet bundleSymbolicNames = new ProjectSet(poms);
        ProjectSet bundleLocations = new ProjectSet(poms);
        ProjectSet jarNames = new ProjectSet(poms);
        ProjectSet serviceProviders = new ProjectSet(poms);

        for (Artifact artifact : artifacts) {

            log.info("Processing artifact: " + artifact);

            // Only consider Compile and Runtime dependencies
            if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope())
                    || Artifact.SCOPE_RUNTIME.equals(artifact.getScope())
                    || Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
                    || (generateTargetPlatform && Artifact.SCOPE_TEST.equals(artifact.getScope())))) {
                log.info("Skipping artifact: " + artifact);
                continue;
            }

            if (artifactTypes == null) {
                artifactTypes = "jar,bundle";
            }
            String types[] = artifactTypes.trim().split("( |\t|\n|\r|\f|,)+");
            Set<String> typeSet = new HashSet<String>(Arrays.asList(types));

            // Only consider JAR and WAR files
            if (!typeSet.contains(artifact.getType())) {
                log.debug("Artifact with unknown type is skipped: " + artifact);
                continue;
            }

            // Exclude artifact if its groupId is excluded or if it's not included
            if (excludedGroupIds.contains(artifact.getGroupId())) {
                log.debug("Artifact groupId is excluded: " + artifact);
                continue;
            }
            if (!includedGroupIds.isEmpty()) {
                if (!includedGroupIds.contains(artifact.getGroupId())) {
                    log.debug("Artifact groupId is not included: " + artifact);
                    continue;
                }
            }

            File artifactFile = artifact.getFile();
            if (!artifactFile.exists()) {
                log.warn("Artifact doesn't exist: " + artifact);
                continue;
            }

            if (log.isDebugEnabled()) {
                log.debug("Processing artifact: " + artifact);
            }

            Manifest customizedMF = findManifest(artifact);

            // Get the bundle name if the artifact is an OSGi bundle
            Manifest mf = null;
            String bundleName = null;
            try {
                mf = BundleUtil.getManifest(artifactFile);
                bundleName = BundleUtil.getBundleSymbolicName(mf);
            } catch (IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }

            if (bundleName != null && customizedMF == null) {

                // Exclude artifact if its file name is excluded
                if (excludedFileNames.contains(artifactFile.getName())) {
                    log.debug("Artifact file is excluded: " + artifact);
                    continue;
                }

                if (generateModules) {
                    // Copy an OSGi bundle as is
                    log.info("Adding OSGi bundle artifact: " + artifact);
                }

                if (!expandThirdPartyBundle || artifact.getGroupId().startsWith("org.apache.tuscany.sca")
                        || artifact.getGroupId().startsWith("org.eclipse")) {
                    if (generateModules) {
                        copyFile(artifactFile, root);
                    }
                    bundleSymbolicNames.add(artifact, bundleName);
                    bundleLocations.add(artifact, artifactFile.getName());
                    jarNames.add(artifact, artifactFile.getName());
                    if (isServiceProvider(mf)) {
                        serviceProviders.add(artifact, bundleName);
                    }
                } else {
                    // Expanding the bundle into a folder

                    setBundleClassPath(mf, artifactFile);

                    int index = artifactFile.getName().lastIndexOf('.');
                    String dirName = artifactFile.getName().substring(0, index);
                    File dir = new File(root, dirName);
                    if (generateModules) {
                        File file = new File(dir, "META-INF");
                        file.mkdirs();
                        file = new File(file, "MANIFEST.MF");

                        FileOutputStream fos = new FileOutputStream(file);
                        write(mf, fos);
                        fos.close();
                        copyFile(artifactFile, dir);
                    }
                    bundleSymbolicNames.add(artifact, bundleName);
                    bundleLocations.add(artifact, dir.getName());
                    jarNames.add(artifact, dirName + "/" + artifactFile.getName());
                    if (isServiceProvider(mf)) {
                        serviceProviders.add(artifact, bundleName);
                    }
                }

            } else if ("war".equals(artifact.getType())) {

                // Exclude artifact if its file name is excluded
                if (excludedFileNames.contains(artifactFile.getName())) {
                    log.debug("Artifact file is excluded: " + artifact);
                    continue;
                }

                if (generateModules) {
                    // Copy a WAR as is
                    log.info("Adding WAR artifact: " + artifact);
                    copyFile(artifactFile, root);
                }
            } else {

                int index = artifactFile.getName().lastIndexOf('.');
                String dirName = artifactFile.getName().substring(0, index);
                File dir = new File(root, dirName);

                // Exclude artifact if its file name is excluded
                if (excludedFileNames.contains(dir.getName())) {
                    log.debug("Artifact file is excluded: " + artifact);
                    continue;
                }

                if (artifactAggregations != null) {
                    boolean aggregated = false;
                    for (ArtifactAggregation group : artifactAggregations) {
                        if (group.matches(artifact)) {
                            group.getArtifacts().add(artifact);
                            aggregated = true;
                            break;
                        }
                    }
                    if (aggregated) {
                        continue;
                    }
                }

                // create manifest directory
                File file = new File(dir, "META-INF");
                if (generateModules) {
                    // Create a bundle directory for a non-OSGi JAR
                    log.info("Adding JAR artifact: " + artifact);

                    file.mkdirs();
                }

                String symbolicName = null;
                if (customizedMF == null) {
                    String version = BundleUtil.osgiVersion(artifact.getVersion());

                    Set<File> jarFiles = new HashSet<File>();
                    jarFiles.add(artifactFile);
                    symbolicName = (artifact.getGroupId() + "." + artifact.getArtifactId());
                    if (generateModules) {
                        mf = BundleUtil.libraryManifest(jarFiles, symbolicName, symbolicName, version, null,
                                this.eclipseBuddyPolicy, this.executionEnvironment);

                        file = new File(file, "MANIFEST.MF");
                        FileOutputStream fos = new FileOutputStream(file);
                        write(mf, fos);
                        fos.close();
                        log.info("Writing generated manifest for: " + artifact + " to " + file);
                    }
                } else {
                    mf = customizedMF;
                    symbolicName = BundleUtil.getBundleSymbolicName(mf);
                    if (symbolicName == null) {
                        throw new MojoExecutionException("Invalid customized MANIFEST.MF for " + artifact);
                    }
                    setBundleClassPath(mf, artifactFile);

                    // re-find the custom MF file and copy it
                    // I can't get the  manifest file from the manifest itself
                    // the Manifest read/write operation seems to be filtering
                    // out some entries that I've added manually????
                    File artifactManifest = null;

                    if (artifactManifests != null) {
                        for (ArtifactManifest m : artifactManifests) {
                            if (m.matches(artifact)) {
                                artifactManifest = m.getManifestFile();
                                break;
                            }
                        }
                    }

                    if (generateModules) {
                        file = new File(file, "MANIFEST.MF");

                        if (artifactManifest != null) {
                            log.info("Copying: " + artifactManifest + " to " + file);
                            copyManifest(artifactManifest, file);
                        } else {
                            FileOutputStream fos = new FileOutputStream(file);
                            write(mf, fos);
                            fos.close();
                            log.info("Writing generated manifest for: " + artifact + " to " + file);
                        }
                    }
                }

                if (generateModules) {
                    copyFile(artifactFile, dir);
                }

                bundleSymbolicNames.add(artifact, symbolicName);
                bundleLocations.add(artifact, dir.getName());
                jarNames.add(artifact, dirName + "/" + artifactFile.getName());
                if (isServiceProvider(mf)) {
                    serviceProviders.add(artifact, symbolicName);
                }
            }
        }

        if (artifactAggregations != null) {
            for (ArtifactAggregation group : artifactAggregations) {
                if (group.getArtifacts().isEmpty()) {
                    continue;
                }
                String symbolicName = group.getSymbolicName();
                String version = group.getVersion();
                File dir = new File(root, symbolicName + "-" + version);
                dir.mkdir();
                Set<File> jarFiles = new HashSet<File>();
                Artifact artifact = null;
                for (Artifact a : group.getArtifacts()) {
                    log.info("Aggragating JAR artifact: " + a);
                    artifact = a;
                    jarFiles.add(a.getFile());
                    copyFile(a.getFile(), dir);
                    jarNames.add(a, symbolicName + "-" + version + "/" + a.getFile().getName());
                }
                Manifest mf = BundleUtil.libraryManifest(jarFiles, symbolicName, symbolicName, version, null,
                        this.eclipseBuddyPolicy, this.executionEnvironment);
                File file = new File(dir, "META-INF");
                file.mkdirs();
                file = new File(file, "MANIFEST.MF");

                FileOutputStream fos = new FileOutputStream(file);
                write(mf, fos);
                fos.close();
                log.info("Written aggregate manifest");
                bundleSymbolicNames.add(artifact, symbolicName);
                bundleLocations.add(artifact, dir.getName());
                if (isServiceProvider(mf)) {
                    serviceProviders.add(artifact, symbolicName);
                }
            }
        }

        if (generateGatewayBundle) {
            generateGatewayBundle(serviceProviders);
        }

        /*
        if (useDistributionName) {
        bundleLocations.nameMap.remove(project.getArtifactId());
        jarNames.nameMap.remove(project.getArtifactId());
        bundleSymbolicNames.nameMap.remove(project.getArtifactId());
        }
        */

        // Generate a PDE target
        if (generateTargetPlatform) {
            generatePDETarget(bundleSymbolicNames, root, log);
        }

        // Generate a plugin.xml referencing the PDE target
        if (generatePlugin) {
            File pluginxml = new File(project.getBasedir(), "plugin.xml");
            FileOutputStream pluginXMLFile = new FileOutputStream(pluginxml);
            writePluginXML(new PrintStream(pluginXMLFile));
            pluginXMLFile.close();
        }

        if (generateConfig) {
            generateEquinoxConfig(bundleLocations, root, log);
        }

        if (generateManifestJar) {
            generateManifestJar(jarNames, root, log);
            generateEquinoxLauncherManifestJar(jarNames, root, log);
        }

        if (generateAntScript) {
            generateANTPath(jarNames, root, log);
        }

        if (generateWhichJars) {
            generateWhichJars(jarNames, root, log);
        }

        if (generateAggregatedBundle) {
            generateAggregatedBundles(bundleLocations, root, log);
        }

    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

}

From source file:org.apache.tuscany.maven.bundle.plugin.BundlesMetaDataBuildMojo.java

License:Apache License

private Set<Artifact> getDependencyArtifacts(MavenProject project)
        throws DependencyTreeBuilderException, ArtifactResolutionException, ArtifactNotFoundException {
    Log log = getLog();
    Set<Artifact> artifacts = new HashSet<Artifact>();
    ArtifactFilter artifactFilter = createResolvingArtifactFilter(Artifact.SCOPE_RUNTIME);

    // TODO: note that filter does not get applied due to MNG-3236

    DependencyNode rootNode = dependencyTreeBuilder.buildDependencyTree(project, local, factory,
            artifactMetadataSource, artifactFilter, artifactCollector);
    CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();
    rootNode.accept(visitor);/*from  ww w . ja va2  s .c  om*/

    // Add included artifacts
    for (Object node : visitor.getNodes()) {
        DependencyNode depNode = (DependencyNode) node;
        int state = depNode.getState();
        if (state == DependencyNode.INCLUDED) {
            Artifact artifact = depNode.getArtifact();
            // Exclude the project artifact to avoid offline resolution failure
            if (!artifact.equals(project.getArtifact())) {
                resolver.resolve(artifact, remoteRepos, local);
                artifacts.add(artifact);
            }
        }
    }
    // Scan for newer versions that are omitted
    for (Object node : visitor.getNodes()) {
        DependencyNode depNode = (DependencyNode) node;
        int state = depNode.getState();
        if (state == DependencyNode.OMITTED_FOR_CONFLICT) {
            Artifact artifact = depNode.getArtifact();
            resolver.resolve(artifact, remoteRepos, local);
            if (state == DependencyNode.OMITTED_FOR_CONFLICT) {
                Artifact related = depNode.getRelatedArtifact();
                if (log.isDebugEnabled()) {
                    log.debug("Dependency node: " + depNode);
                }
                // Compare the version
                ArtifactVersion v1 = new DefaultArtifactVersion(artifact.getVersion());
                ArtifactVersion v2 = new DefaultArtifactVersion(related.getVersion());
                if (v1.compareTo(v2) > 0) {
                    // Only add newer version if it is omitted for conflict
                    if (artifacts.add(artifact)) {
                        log.info("Dependency node added: " + depNode);
                    }
                }
            }
        }
    }
    return artifacts;
}

From source file:org.apache.tuscany.maven.bundle.plugin.ModuleBundlesBuildMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    Log log = getLog();

    Set<Artifact> artifacts = null;
    if (includeConflictingDepedencies) {
        try {//from   w  w  w . j a  va  2 s  .  co m
            artifacts = getDependencyArtifacts(project);
        } catch (Exception e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    } else {
        artifacts = project.getArtifacts();
    }

    try {

        // Create the target directory
        File root;
        if (targetDirectory == null) {
            root = new File(project.getBuild().getDirectory(), "plugins/");
        } else {
            root = targetDirectory;
        }
        root.mkdirs();

        // Build sets of exclude directories and included/excluded/groupids
        Set<String> excludedFileNames = new HashSet<String>();
        if (excludeDirectories != null) {
            for (File f : excludeDirectories) {
                if (f.isDirectory()) {
                    for (String n : f.list()) {
                        excludedFileNames.add(n);
                    }
                }
            }
        }
        Set<String> includedGroupIds = new HashSet<String>();
        if (includeGroupIds != null) {
            for (String g : includeGroupIds) {
                includedGroupIds.add(g);
            }
        }
        Set<String> excludedGroupIds = new HashSet<String>();
        if (excludeGroupIds != null) {
            for (String g : excludeGroupIds) {
                excludedGroupIds.add(g);
            }
        }

        // Find all the distribution poms
        List<MavenProject> poms = new ArrayList<MavenProject>();
        poms.add(project);
        if (useDistributionName) {
            for (Object o : project.getArtifacts()) {
                Artifact artifact = (Artifact) o;
                if ("pom".equals(artifact.getType()) && artifact.getGroupId().equals(project.getGroupId())
                        && artifact.getArtifactId().startsWith("tuscany-feature-")) {
                    log.info("Dependent distribution: " + artifact);
                    MavenProject pomProject = buildProject(artifact);
                    poms.add(pomProject);
                    // log.info(pomProject.getArtifactMap().toString());
                }
            }
        }

        // Process all the dependency artifacts
        ProjectSet bundleSymbolicNames = new ProjectSet(poms);
        ProjectSet bundleLocations = new ProjectSet(poms);
        ProjectSet jarNames = new ProjectSet(poms);
        ProjectSet serviceProviders = new ProjectSet(poms);

        for (Artifact artifact : artifacts) {

            // Only consider Compile and Runtime dependencies
            if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope())
                    || Artifact.SCOPE_RUNTIME.equals(artifact.getScope())
                    || Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
                    || (generateTargetPlatform && Artifact.SCOPE_TEST.equals(artifact.getScope())))) {
                log.info("Skipping artifact: " + artifact);
                continue;
            }

            if (artifactTypes == null) {
                artifactTypes = "jar,bundle";
            }
            String types[] = artifactTypes.trim().split("( |\t|\n|\r|\f|,)+");
            Set<String> typeSet = new HashSet<String>(Arrays.asList(types));

            // Only consider JAR and WAR files
            if (!typeSet.contains(artifact.getType())) {
                log.debug("Artifact with unknown type is skipped: " + artifact);
                continue;
            }

            // Exclude artifact if its groupId is excluded or if it's not included
            if (excludedGroupIds.contains(artifact.getGroupId())) {
                log.debug("Artifact groupId is excluded: " + artifact);
                continue;
            }
            if (!includedGroupIds.isEmpty()) {
                if (!includedGroupIds.contains(artifact.getGroupId())) {
                    log.debug("Artifact groupId is not included: " + artifact);
                    continue;
                }
            }

            File artifactFile = artifact.getFile();
            if (!artifactFile.exists()) {
                log.warn("Artifact doesn't exist: " + artifact);
                continue;
            }

            if (log.isDebugEnabled()) {
                log.debug("Processing artifact: " + artifact);
            }

            Manifest customizedMF = findManifest(artifact);

            // Get the bundle name if the artifact is an OSGi bundle
            Manifest mf = null;
            String bundleName = null;
            try {
                mf = BundleUtil.getManifest(artifactFile);
                bundleName = BundleUtil.getBundleSymbolicName(mf);
            } catch (IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }

            if (bundleName != null && customizedMF == null) {

                // Exclude artifact if its file name is excluded
                if (excludedFileNames.contains(artifactFile.getName())) {
                    log.debug("Artifact file is excluded: " + artifact);
                    continue;
                }

                // Copy an OSGi bundle as is
                log.info("Adding OSGi bundle artifact: " + artifact);

                if (!expandThirdPartyBundle || artifact.getGroupId().startsWith("org.apache.tuscany.sca")
                        || artifact.getGroupId().startsWith("org.eclipse")) {
                    copyFile(artifactFile, root);
                    bundleSymbolicNames.add(artifact, bundleName);
                    bundleLocations.add(artifact, artifactFile.getName());
                    jarNames.add(artifact, artifactFile.getName());
                    if (isServiceProvider(mf)) {
                        serviceProviders.add(artifact, bundleName);
                    }
                } else {
                    // Expanding the bundle into a folder

                    setBundleClassPath(mf, artifactFile);

                    int index = artifactFile.getName().lastIndexOf('.');
                    String dirName = artifactFile.getName().substring(0, index);
                    File dir = new File(root, dirName);

                    File file = new File(dir, "META-INF");
                    file.mkdirs();
                    file = new File(file, "MANIFEST.MF");

                    FileOutputStream fos = new FileOutputStream(file);
                    write(mf, fos);
                    fos.close();
                    copyFile(artifactFile, dir);
                    bundleSymbolicNames.add(artifact, bundleName);
                    bundleLocations.add(artifact, dir.getName());
                    jarNames.add(artifact, dirName + "/" + artifactFile.getName());
                    if (isServiceProvider(mf)) {
                        serviceProviders.add(artifact, bundleName);
                    }
                }

            } else if ("war".equals(artifact.getType())) {

                // Exclude artifact if its file name is excluded
                if (excludedFileNames.contains(artifactFile.getName())) {
                    log.debug("Artifact file is excluded: " + artifact);
                    continue;
                }

                // Copy a WAR as is
                log.info("Adding WAR artifact: " + artifact);
                copyFile(artifactFile, root);

            } else {

                int index = artifactFile.getName().lastIndexOf('.');
                String dirName = artifactFile.getName().substring(0, index);
                File dir = new File(root, dirName);

                // Exclude artifact if its file name is excluded
                if (excludedFileNames.contains(dir.getName())) {
                    log.debug("Artifact file is excluded: " + artifact);
                    continue;
                }

                if (artifactAggregations != null) {
                    boolean aggregated = false;
                    for (ArtifactAggregation group : artifactAggregations) {
                        if (group.matches(artifact)) {
                            group.getArtifacts().add(artifact);
                            aggregated = true;
                            break;
                        }
                    }
                    if (aggregated) {
                        continue;
                    }
                }

                // Create a bundle directory for a non-OSGi JAR
                log.info("Adding JAR artifact: " + artifact);

                // create manifest directory
                File file = new File(dir, "META-INF");
                file.mkdirs();

                String symbolicName = null;
                if (customizedMF == null) {
                    String version = BundleUtil.osgiVersion(artifact.getVersion());

                    Set<File> jarFiles = new HashSet<File>();
                    jarFiles.add(artifactFile);
                    symbolicName = (artifact.getGroupId() + "." + artifact.getArtifactId());
                    mf = BundleUtil.libraryManifest(jarFiles, symbolicName, symbolicName, version, null,
                            this.eclipseBuddyPolicy, this.executionEnvironment);

                    file = new File(file, "MANIFEST.MF");
                    FileOutputStream fos = new FileOutputStream(file);
                    write(mf, fos);
                    fos.close();
                    log.info("Writing generated manifest for: " + artifact + " to " + file);
                } else {
                    mf = customizedMF;
                    symbolicName = BundleUtil.getBundleSymbolicName(mf);
                    if (symbolicName == null) {
                        throw new MojoExecutionException("Invalid customized MANIFEST.MF for " + artifact);
                    }
                    setBundleClassPath(mf, artifactFile);

                    // re-find the custom MF file and copy it
                    // I can't get the  manifest file from the manifest itself
                    // the Manifest read/write operation seems to be filtering
                    // out some entries that I've added manually????
                    File artifactManifest = null;

                    if (artifactManifests != null) {
                        for (ArtifactManifest m : artifactManifests) {
                            if (m.matches(artifact)) {
                                artifactManifest = m.getManifestFile();
                                break;
                            }
                        }
                    }

                    file = new File(file, "MANIFEST.MF");

                    if (artifactManifest != null) {
                        log.info("Copying: " + artifactManifest + " to " + file);
                        copyManifest(artifactManifest, file);
                    } else {
                        FileOutputStream fos = new FileOutputStream(file);
                        write(mf, fos);
                        fos.close();
                        log.info("Writing generated manifest for: " + artifact + " to " + file);
                    }
                }

                copyFile(artifactFile, dir);
                bundleSymbolicNames.add(artifact, symbolicName);
                bundleLocations.add(artifact, dir.getName());
                jarNames.add(artifact, dirName + "/" + artifactFile.getName());
                if (isServiceProvider(mf)) {
                    serviceProviders.add(artifact, symbolicName);
                }
            }
        }

        if (artifactAggregations != null) {
            for (ArtifactAggregation group : artifactAggregations) {
                if (group.getArtifacts().isEmpty()) {
                    continue;
                }
                String symbolicName = group.getSymbolicName();
                String version = group.getVersion();
                File dir = new File(root, symbolicName + "-" + version);
                dir.mkdir();
                Set<File> jarFiles = new HashSet<File>();
                Artifact artifact = null;
                for (Artifact a : group.getArtifacts()) {
                    log.info("Aggragating JAR artifact: " + a);
                    artifact = a;
                    jarFiles.add(a.getFile());
                    copyFile(a.getFile(), dir);
                    jarNames.add(a, symbolicName + "-" + version + "/" + a.getFile().getName());
                }
                Manifest mf = BundleUtil.libraryManifest(jarFiles, symbolicName, symbolicName, version, null,
                        this.eclipseBuddyPolicy, this.executionEnvironment);
                File file = new File(dir, "META-INF");
                file.mkdirs();
                file = new File(file, "MANIFEST.MF");

                FileOutputStream fos = new FileOutputStream(file);
                write(mf, fos);
                fos.close();
                log.info("Written aggregate manifest");
                bundleSymbolicNames.add(artifact, symbolicName);
                bundleLocations.add(artifact, dir.getName());
                if (isServiceProvider(mf)) {
                    serviceProviders.add(artifact, symbolicName);
                }
            }
        }

        if (generateGatewayBundle) {
            generateGatewayBundle(serviceProviders);
        }

        /*
        if (useDistributionName) {
        bundleLocations.nameMap.remove(project.getArtifactId());
        jarNames.nameMap.remove(project.getArtifactId());
        bundleSymbolicNames.nameMap.remove(project.getArtifactId());
        }
        */

        // Generate a PDE target
        if (generateTargetPlatform) {
            generatePDETarget(bundleSymbolicNames, root, log);
        }

        // Generate a plugin.xml referencing the PDE target
        if (generatePlugin) {
            File pluginxml = new File(project.getBasedir(), "plugin.xml");
            FileOutputStream pluginXMLFile = new FileOutputStream(pluginxml);
            writePluginXML(new PrintStream(pluginXMLFile));
            pluginXMLFile.close();
        }

        if (generateConfig) {
            generateEquinoxConfig(bundleLocations, root, log);
        }

        if (generateManifestJar) {
            generateManifestJar(jarNames, root, log);
            generateEquinoxLauncherManifestJar(jarNames, root, log);
        }

        if (generateAntScript) {
            generateANTPath(jarNames, root, log);
        }

        if (generateAggregatedBundle) {
            generateAggregatedBundles(bundleLocations, root, log);
        }

    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

}

From source file:org.apache.tuscany.maven.bundle.plugin.ThirdPartyBundleBuildMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    Log log = getLog();

    String projectGroupId = project.getGroupId();
    Set<File> jarFiles = new HashSet<File>();
    for (Object o : project.getArtifacts()) {
        Artifact artifact = (Artifact) o;

        if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope())
                || Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
            if (log.isDebugEnabled()) {
                log.debug("Skipping artifact: " + artifact);
            }//from  ww w. ja v a  2s  . c o m
            continue;
        }
        if (!"jar".equals(artifact.getType())) {
            continue;
        }
        if (projectGroupId.equals(artifact.getGroupId())) {
            continue;
        }

        if (log.isDebugEnabled()) {
            log.debug("Artifact: " + artifact);
        }
        String bundleName = null;
        try {
            bundleName = BundleUtil.getBundleSymbolicName(artifact.getFile());
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        if (bundleName == null || true) {
            if (artifact.getFile().exists()) {
                log.info("Adding third party jar: " + artifact);
                jarFiles.add(artifact.getFile());
            } else {
                log.warn("Third party jar not found: " + artifact);
            }
        }
    }

    try {
        String version = BundleUtil.osgiVersion(project.getVersion());

        Manifest mf = BundleUtil.libraryManifest(jarFiles, project.getName(), symbolicName, version, "lib");
        File file = new File(project.getBasedir(), "META-INF");
        file.mkdir();
        file = new File(file, "MANIFEST.MF");
        if (log.isDebugEnabled()) {
            log.debug("Generating " + file);
        }

        FileOutputStream fos = new FileOutputStream(file);
        write(mf, fos);
        fos.close();

        File lib = new File(project.getBasedir(), "lib");
        if (lib.isDirectory()) {
            for (File c : lib.listFiles()) {
                c.delete();
            }
        }
        lib.mkdir();
        byte[] buf = new byte[4096];
        for (File jar : jarFiles) {
            File jarFile = new File(lib, jar.getName());
            if (log.isDebugEnabled()) {
                log.debug("Copying " + jar + " to " + jarFile);
            }
            FileInputStream in = new FileInputStream(jar);
            FileOutputStream out = new FileOutputStream(jarFile);
            for (;;) {
                int len = in.read(buf);
                if (len > 0) {
                    out.write(buf, 0, len);
                } else {
                    break;
                }
            }
            in.close();
            out.close();
        }
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

}

From source file:org.apache.tuscany.maven.plugin.surefire.OSGiSurefirePlugin.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    if (project.getPackaging().equals("pom")) {
        return;//from   w  ww .  j  a  v a2 s .c om
    }

    if (verifyParameters()) {
        OSGiSurefireBooter surefireBooter = constructSurefireBooter();

        Log log = getLog();
        Set<String> jarFiles = new HashSet<String>();

        /*
        for (Object o : project.getArtifacts()) {
        Artifact a = (Artifact)o;
        if ("pom".equals(a.getType())) {
            // Skip pom projects
            continue;
        }
        try {
            if (log.isDebugEnabled()) {
                log.debug("Adding: " + a);
            }
            jarFiles.add(a.getFile().toURI().toURL());
        } catch (MalformedURLException e) {
            getLog().error(e);
        }
        }
        */

        /*
         * Add org.apache.tuscany.sca:tuscany-extensibility-osgi module
         */
        Artifact ext = getArtifact("org.apache.tuscany.sca", "tuscany-extensibility-equinox");
        if (log.isDebugEnabled()) {
            log.debug("Adding: " + ext);
        }
        jarFiles.add(ext.getFile().getAbsolutePath());

        Artifact con = getArtifact("org.apache.tuscany.sca", "tuscany-contribution-osgi");
        if (log.isDebugEnabled()) {
            log.debug("Adding: " + con);
        }
        jarFiles.add(con.getFile().getAbsolutePath());

        String name = project.getBuild().getFinalName();
        String mainBundleName = null;
        File mainJar = new File(project.getBuild().getDirectory(), name + "-osgi.jar");
        File testJar = new File(project.getBuild().getDirectory(), name + "-osgi-tests.jar");
        try {
            Manifest manifest = createMainBundle();
            mainBundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
            int sc = mainBundleName.indexOf(';');
            if (sc != -1) {
                mainBundleName = mainBundleName.substring(0, sc);
            }
            generateJar(classesDirectory, mainJar, manifest);
            Manifest testManifest = createTestFragment(manifest);
            generateJar(testClassesDirectory, testJar, testManifest);
            jarFiles.add(mainJar.getAbsolutePath());
            jarFiles.add(testJar.getAbsolutePath());
        } catch (IOException e) {
            getLog().error(e);
        }

        if (log.isDebugEnabled()) {
            log.debug("Main bundle: " + mainBundleName);
        }
        surefireBooter.setMainBundleName(mainBundleName);
        for (String url : jarFiles) {
            surefireBooter.addClassPathUrl(url);
        }

        getLog().info("Surefire report directory: " + reportsDirectory);

        int result;
        try {
            result = surefireBooter.run();
        } catch (SurefireBooterForkException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        } catch (SurefireExecutionException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }

        if (originalSystemProperties != null && !surefireBooter.isForking()) {
            // restore system properties, only makes sense when not forking..
            System.setProperties(originalSystemProperties);
        }

        if (result == 0)
            return;

        String msg;

        if (result == OSGiSurefireBooter.NO_TESTS_EXIT_CODE) {
            if ((failIfNoTests == null) || !failIfNoTests.booleanValue())
                return;
            // TODO: i18n
            throw new MojoFailureException(
                    "No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)");
        } else {
            // TODO: i18n
            msg = "There are test failures.\n\nPlease refer to " + reportsDirectory
                    + " for the individual test results.";

        }

        if (testFailureIgnore) {
            getLog().error(msg);
        } else {
            throw new MojoFailureException(msg);
        }
    }
}

From source file:org.arakhne.maven.ExtendedArtifact.java

License:Open Source License

/** Replies the people with the given login.
 * This function checks the peoples replied
 * by {@link #getDevelopers()} and//  w  w  w . ja v  a 2 s  .  c o  m
 * {@link #getContributors()}.
 * 
 * @param login
 * @param logger
 * @return the people or <code>null</code>
 */
public Contributor getPeople(String login, Log logger) {
    for (Developer devel : getDevelopers()) {
        if (devel != null) {
            if (logger != null && logger.isDebugEnabled()) {
                logger.debug("Comparing '" + login //$NON-NLS-1$
                        + " to the developer [ID=" + devel.getId() //$NON-NLS-1$
                        + ";NAME=" + devel.getName() //$NON-NLS-1$
                        + ";EMAIL=" + devel.getEmail() //$NON-NLS-1$
                        + "]"); //$NON-NLS-1$
            }
            String idprop = null;
            Properties props = devel.getProperties();
            if (props != null) {
                idprop = props.getProperty("id", null); //$NON-NLS-1$
                if (idprop == null)
                    idprop = props.getProperty("login", null); //$NON-NLS-1$
            }
            if (login.equals(devel.getId()) || login.equals(devel.getName()) || login.equals(devel.getEmail())
                    || login.equals(idprop)) {
                if (logger != null && logger.isDebugEnabled()) {
                    logger.debug("Selecting the developer [ID=" + devel.getId() //$NON-NLS-1$
                            + ";NAME=" + devel.getName() //$NON-NLS-1$
                            + ";EMAIL=" + devel.getEmail() //$NON-NLS-1$
                            + "]"); //$NON-NLS-1$
                }
                return devel;
            }
        }
    }
    for (Contributor contrib : getContributors()) {
        if (contrib != null) {
            if (logger != null && logger.isDebugEnabled()) {
                logger.debug("Comparing '" + login //$NON-NLS-1$
                        + " to the contributor [NAME=" + contrib.getName() //$NON-NLS-1$
                        + ";EMAIL=" + contrib.getEmail() //$NON-NLS-1$
                        + "]"); //$NON-NLS-1$
            }
            String idprop = null;
            Properties props = contrib.getProperties();
            if (props != null) {
                idprop = props.getProperty("id", null); //$NON-NLS-1$
                if (idprop == null)
                    idprop = props.getProperty("login", null); //$NON-NLS-1$
            }
            if (login.equals(contrib.getName()) || login.equals(contrib.getEmail()) || login.equals(idprop)) {
                if (logger != null && logger.isDebugEnabled()) {
                    logger.debug("Selecting the contributor [NAME=" + contrib.getName() //$NON-NLS-1$
                            + ";EMAIL=" + contrib.getEmail() //$NON-NLS-1$
                            + "]"); //$NON-NLS-1$
                }
                return contrib;
            }
        }
    }
    if (logger != null && logger.isDebugEnabled()) {
        logger.debug("No people found for: " + login); //$NON-NLS-1$
        logger.debug("Developers are: " + this.developers.toString()); //$NON-NLS-1$
        logger.debug("Contributors are: " + this.contributors.toString()); //$NON-NLS-1$
    }
    return null;
}

From source file:org.bedework.util.deployment.Utils.java

License:Open Source License

public Utils(final Log logger) {
    this.logger = logger;
    debug = logger.isDebugEnabled();
}