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

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

Introduction

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

Prototype

void info(Throwable error);

Source Link

Document

Send an exception to the user in the info error level.
The stack trace for this exception will be output when this error level is enabled.

Usage

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 {/*from www .  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  w ww . jav a 2 s . c o  m*/

    // 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.BundlesMetaDataBuildMojo.java

License:Apache License

private void generateANTPath(ProjectSet jarNames, File root, Log log)
        throws FileNotFoundException, IOException {
    for (Map.Entry<String, Set<String>> e : jarNames.nameMap.entrySet()) {
        Set<String> jars = e.getValue();
        File feature = new File(root,
                "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : ""));
        feature.mkdirs();/*from w w  w .j ava  2s  . c  om*/
        File antPath = new File(feature, "build-path.xml");
        log.info("Generating ANT build path: " + antPath.getCanonicalPath());
        FileOutputStream fos = new FileOutputStream(antPath);
        PrintStream ps = new PrintStream(fos);
        // ps.println(XML_PI);
        ps.println(ASL_HEADER);
        String name = trim(e.getKey());
        ps.println("<project name=\"" + name + "\">");
        ps.println("  <property name=\"tuscany.manifest\" value=\""
                + new File(feature, manifestJarName).getCanonicalPath() + "\"/>");
        ps.println("  <dirname property=\"" + name + ".basedir\" file=\"${ant.file." + name + "}\"/>");
        ps.println("  <path id=\"" + name + ".path" + "\">");
        ps.println("    <fileset dir=\"${" + name + ".basedir}../../../modules\">");
        for (String jar : jars) {
            ps.println("      <include name=\"" + jar + "\"/>");
        }
        ps.println("    </fileset>");
        ps.println("  </path>");
        ps.println("</project>");
    }
}

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

License:Apache License

private void generateWhichJars(ProjectSet jarNames, File root, Log log)
        throws FileNotFoundException, IOException {
    for (Map.Entry<String, Set<String>> e : jarNames.nameMap.entrySet()) {
        Set<String> jars = e.getValue();
        File feature = new File(root,
                "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : ""));
        feature.mkdirs();/*  w w w . j a  v  a2  s  . c  o m*/
        File whichJarsPath = new File(feature, "which-jars");
        log.info("Generating Which Jars: " + whichJarsPath.getCanonicalPath());
        FileOutputStream fos = new FileOutputStream(whichJarsPath);
        PrintStream ps = new PrintStream(fos);

        ps.println(ASL_HEADER);
        String name = trim(e.getKey());
        ps.println("Jars required to enable extension: " + name);
        ps.println("");
        for (String jar : jars) {
            ps.println(jar);
        }
    }
}

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

License:Apache License

private void generateManifestJar(ProjectSet jarNames, File root, Log log)
        throws FileNotFoundException, IOException {
    for (Map.Entry<String, Set<String>> e : jarNames.nameMap.entrySet()) {
        MavenProject pom = jarNames.getProject(e.getKey());
        Set<String> jars = e.getValue();
        String name = trim(e.getKey());
        File feature = new File(root,
                "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : ""));
        feature.mkdirs();/*ww w  .  j a va  2 s.  c o  m*/
        String manifestName = name + "-manifest.jar";
        File mfJar = new File(feature, manifestName);
        log.info("Generating manifest jar: " + mfJar.getCanonicalPath());
        FileOutputStream fos = new FileOutputStream(mfJar);
        Manifest mf = new Manifest();
        StringBuffer cp = new StringBuffer();
        String path = (useDistributionName ? "../../" : "../") + root.getName();
        for (String jar : jars) {
            cp.append(path).append('/').append(jar).append(' ');
        }
        if (cp.length() > 0) {
            cp.deleteCharAt(cp.length() - 1);
        }
        Attributes attrs = mf.getMainAttributes();
        attrs.putValue("Manifest-Version", "1.0");
        attrs.putValue("Implementation-Title", pom.getName());
        attrs.putValue("Implementation-Vendor", "The Apache Software Foundation");
        attrs.putValue("Implementation-Vendor-Id", "org.apache");
        attrs.putValue("Implementation-Version", pom.getVersion());
        attrs.putValue("Class-Path", cp.toString());
        attrs.putValue("Main-Class", "org.apache.tuscany.sca.node.launcher.NodeMain");
        JarOutputStream jos = new JarOutputStream(fos, mf);
        addFileToJar(jos, "META-INF/LICENSE", getClass().getResource("LICENSE.txt"));
        addFileToJar(jos, "META-INF/NOTICE", getClass().getResource("NOTICE.txt"));
        jos.close();
    }
}

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

License:Apache License

private void generateEquinoxLauncherManifestJar(ProjectSet jarNames, File root, Log log) throws Exception {
    String equinoxLauncher = "org.apache.tuscany.sca:tuscany-node-launcher-equinox";
    Artifact artifact = (Artifact) project.getArtifactMap().get(equinoxLauncher);
    if (artifact == null) {
        return;//from   w  w w. ja  v  a  2  s .c o  m
    }
    Set artifacts = resolveTransitively(artifact).getArtifacts();
    File feature = new File(root, "../" + featuresName + "/");
    feature.mkdirs();
    File mfJar = new File(feature, equinoxManifestJarName);
    log.info("Generating equinox manifest jar: " + mfJar.getCanonicalPath());
    FileOutputStream fos = new FileOutputStream(mfJar);
    Manifest mf = new Manifest();
    StringBuffer cp = new StringBuffer();
    String path = "../" + root.getName();

    for (Object o : artifacts) {
        Artifact a = (Artifact) o;
        if (!Artifact.SCOPE_TEST.equals(a.getScope())) {
            String id = ArtifactUtils.versionlessKey(a);
            String jar = jarNames.artifactToNameMap.get(id);
            if (jar != null) {
                cp.append(path).append('/').append(jar).append(' ');
            }
        }
    }
    if (cp.length() > 0) {
        cp.deleteCharAt(cp.length() - 1);
    }
    Attributes attrs = mf.getMainAttributes();
    attrs.putValue("Manifest-Version", "1.0");
    attrs.putValue("Implementation-Title", artifact.getId());
    attrs.putValue("Implementation-Vendor", "The Apache Software Foundation");
    attrs.putValue("Implementation-Vendor-Id", "org.apache");
    attrs.putValue("Implementation-Version", artifact.getVersion());
    attrs.putValue("Class-Path", cp.toString());
    attrs.putValue("Main-Class", "org.apache.tuscany.sca.node.equinox.launcher.NodeMain");
    JarOutputStream jos = new JarOutputStream(fos, mf);
    addFileToJar(jos, "META-INF/LICENSE", getClass().getResource("LICENSE.txt"));
    addFileToJar(jos, "META-INF/NOTICE", getClass().getResource("NOTICE.txt"));
    jos.close();
}

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

License:Apache License

private void generateEquinoxConfig(ProjectSet bundleLocations, File root, Log log) throws IOException {
    for (Map.Entry<String, Set<String>> e : bundleLocations.nameMap.entrySet()) {
        Set<String> locations = new HashSet<String>(e.getValue());
        if (generateGatewayBundle) {
            locations.add("tuscany-gateway-" + project.getVersion() + ".jar");
        }/*from www  . j a  v a  2 s .  c  om*/
        File feature = new File(root,
                "../" + featuresName + "/" + (useDistributionName ? trim(e.getKey()) : ""));
        File config = new File(feature, "configuration");
        config.mkdirs();
        File ini = new File(config, "config.ini");
        log.info("Generating configuation: " + ini.getCanonicalPath());
        FileOutputStream fos = new FileOutputStream(ini);
        PrintStream ps = new PrintStream(fos);
        int size = locations.size();
        if (size > 0) {
            ps.println("osgi.bundles=\\");
            int count = 0;
            for (String f : locations) {
                if (f.startsWith("osgi")) {
                    count++;
                    continue;
                }
                ps.print("    ");
                ps.print(f);
                // FIXME: We should not add @start for fragments
                if (generateBundleStart) {
                    ps.print("@:start");
                }
                if (count == size - 1) {
                    // Last one
                    ps.println();
                } else {
                    ps.println(",\\");
                }
                count++;
            }
        }
        ps.println("eclipse.ignoreApp=true");
        // Do not shutdown
        ps.println("osgi.noShutdown=true");
        ps.close();
    }
}

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

License:Apache License

private void generateAggregatedBundles(ProjectSet bundleLocations, File root, Log log) throws Exception {
    for (Map.Entry<String, Set<String>> e : bundleLocations.nameMap.entrySet()) {
        Set<String> locations = new HashSet<String>(e.getValue());
        String featureName = (useDistributionName ? trim(e.getKey()) : "");
        File feature = new File(root, "../" + featuresName + "/" + featureName);
        //            String bundleFileName = "tuscany-bundle-" + featureName + ".jar";
        //            if ("".equals(featureName)) {
        //                bundleFileName = "tuscany-bundle.jar";
        //            }
        String bundleFileName = "tuscany-bundle.jar";
        File bundleFile = new File(feature, bundleFileName);
        log.info("Generating aggregated OSGi bundle: " + bundleFile);
        File[] files = new File[locations.size()];
        int i = 0;
        for (String child : locations) {
            files[i++] = new File(root, child);
        }//w w  w .j av a2s  .c om
        String bundleVersion = "2.0.0";
        String bundleName = "org.apache.tuscany.sca.bundle";

        //            String bundleName = "org.apache.tuscany.sca.bundle." + featureName;
        //            if ("".equals(featureName)) {
        //                bundleName = "org.apache.tuscany.sca.bundle";
        //            }
        BundleAggregatorMojo.aggregateBundles(log, root, files, bundleFile, bundleName, bundleVersion);
    }
}

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

License:Apache License

private void generatePDETarget(ProjectSet bundleSymbolicNames, File root, Log log)
        throws FileNotFoundException, IOException {
    for (Map.Entry<String, Set<String>> e : bundleSymbolicNames.nameMap.entrySet()) {
        Set<String> bundles = new HashSet<String>(e.getValue());
        String name = trim(e.getKey());
        File feature = new File(root, "../" + featuresName + "/" + (useDistributionName ? name : ""));
        feature.mkdirs();// www.  j a v a  2s.  c o m
        File target = new File(feature, "tuscany.target");
        log.info("Generating target definition: " + target.getCanonicalPath());
        FileOutputStream targetFile = new FileOutputStream(target);
        if (!bundles.contains("org.eclipse.osgi")) {
            bundles.add("org.eclipse.osgi");
        }
        if (generateGatewayBundle) {
            bundles.add(GATEWAY_BUNDLE);
        }
        writeTarget(new PrintStream(targetFile), name, bundles, eclipseFeatures);
        targetFile.close();

        // Generate the PDE target definition file for PDE 3.5
        File target35 = new File(feature, "tuscany-pde35.target");
        log.info("Generating target definition: " + target35.getCanonicalPath());
        FileOutputStream target35File = new FileOutputStream(target35);
        writePDE35Target(new PrintStream(target35File), name, bundles, eclipseFeatures);
        target35File.close();

    }
}

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 ww. java2s .  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;
        }
        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);
    }

}