diff options
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.5.2/tools/maven')
31 files changed, 4609 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/LICENSE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/NOTICE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/pom.xml new file mode 100644 index 0000000000..57a9a9b0ab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/pom.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-maven-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-maven-ant-generator</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany SCA Ant Build Generator Maven Plugin</name> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-settings</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>2.0.5</version> + </dependency> + + </dependencies> +</project> diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java new file mode 100644 index 0000000000..b44dd16a91 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java @@ -0,0 +1,541 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.tools.ant.generator.plugin; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.model.FileSet; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * A Maven plugin that generates an Ant build.xml file for Tuscany SCA samples. + * + * Build dependencies and additional build steps like WSDL2Java for example are + * automatically determined from the pom.xml file describing the module's Maven build. + * + * @version $Rev$ $Date$ + * @goal generate + * @phase generate-sources + * @requiresDependencyResolution test + * @description Generate Ant build script for an SCA project + */ +public class AntGeneratorMojo extends AbstractMojo { + + /** + * The project to generate an Ant build for. + * + * @parameter expression="${project}" + * @required + */ + private MavenProject project; + + /** + * Used for resolving artifacts + * + * @component + */ + private ArtifactResolver resolver; + + /** + * Factory for creating artifact objects + * + * @component + */ + private ArtifactFactory factory; + + /** + * The local repository where the artifacts are located + * + * @parameter expression="${localRepository}" + * @required + */ + private ArtifactRepository localRepository; + + /** + * The remote repositories where artifacts are located + * + * @parameter expression="${project.remoteArtifactRepositories}" + */ + private List remoteRepositories; + + /** + * The current user system settings for use in Maven. + * + * @parameter expression="${settings}" + * @required + * @readonly + */ + private Settings settings; + + /** + * The main class name. + * @parameter + */ + private String mainClass; + + /** + * If set true then only the dependency file is created. The dependency + * file can then be included in a hand generated build.xml file + * @parameter + */ + private Boolean buildDependencyFileOnly; + + /** + * The build.xml file to generate. + * @parameter expression="${basedir}/build.xml" + */ + private String buildFile; + + /** + * The build-dependency.xml file to generate. + * @parameter expression="${basedir}/build-dependency.xml" + */ + private String buildDependencyFile; + + /** + * The path to the root dir so that build.xml files can be generated at any level + * in the distribution hierarchy + * @parameter expression="../.." + */ + private String pathToRootDir; + + public void execute() throws MojoExecutionException { + if ((buildDependencyFileOnly != null) && + (buildDependencyFileOnly == true)){ + generateBuildDependencyFile(); + } else { + generateBuildFile(); + } + } + + /** + * Generate Ant build dependency XML file + */ + private void generateBuildDependencyFile() throws MojoExecutionException { + + getLog().info("Generating " + buildDependencyFile); + + // Open the target build-dependency.xml file + File targetFile = new File(buildDependencyFile); + PrintWriter pw; + try { + pw = new PrintWriter(new FileOutputStream(targetFile)); + } catch (FileNotFoundException e) { + throw new MojoExecutionException(e.toString()); + } + + // Generate the Apache license header + generateLicenseHeader(pw); + + // Generate Ant filesets representing the build dependencies + generateBuildDependencies(pw); + + pw.close(); + } + + /** + * Generate Ant build XML file + */ + private void generateBuildFile() throws MojoExecutionException { + + getLog().info("Generating " + buildFile); + + // Open the target build.xml file + File targetFile = new File(buildFile); + PrintWriter pw; + try { + pw = new PrintWriter(new FileOutputStream(targetFile)); + } catch (FileNotFoundException e) { + throw new MojoExecutionException(e.toString()); + } + + // Determine the project packaging + String packaging = project.getPackaging().toLowerCase(); + + // Generate the Apache license header + generateLicenseHeader(pw); + + pw.println("<project name=\"" + project.getArtifactId() + "\" default=\"compile\">"); + pw.println(); + + // Generate the compile target + int base = project.getBasedir().toString().length() + 1; + pw.println(" <target name=\"compile\">"); + pw.println(" <mkdir dir=\"target/classes\"/>"); + + // Generate any pre-compilation tasks + generatePreCompileTasks(pw); + + // Generate the compile task + pw.println(" <javac destdir=\"target/classes\" debug=\"on\" source=\"1.5\" target=\"1.5\">"); + for (String source: (List<String>)project.getCompileSourceRoots()) { + if (source.length() > base) { + source = source.substring(base); + } else { + source = "."; + } + pw.println(" <src path=\"" + source + "\"/>"); + } + pw.println(" <classpath>"); + pw.println(" <fileset refid=\"tuscany.jars\"/>"); + pw.println(" <fileset refid=\"3rdparty.jars\"/>"); + pw.println(" </classpath>"); + pw.println(" </javac>"); + pw.println(" <copy todir=\"target/classes\">"); + for (FileSet resource: (List<FileSet>)project.getResources()) { + String source = resource.getDirectory(); + if (source.length() > base) { + source = source.substring(base); + + if (source.equals(".")){ + pw.println(" <fileset dir=\".\" includes=\"*\" excludes=\"src, target, pom.xml, build.xml\"/>"); + } else { + pw.println(" <fileset dir=\"" + source + "\"/>"); + } + } else { + if (project.getResources().size() > 1) { + break; + } + pw.println(" <fileset dir=\".\" excludes=\"**/*.java, pom.xml, build.xml, target\"/>"); + source = "."; + } + } + pw.println(" </copy>"); + + // Build a JAR + if (packaging.equals("jar")) { + pw.println(" <jar destfile=\"target/" + project.getArtifactId() + ".jar\" basedir=\"target/classes\">"); + pw.println(" <manifest>"); + if (mainClass != null) { + pw.println(" <attribute name=\"Main-Class\" value=\"" + mainClass + "\"/>"); + } + pw.println(" </manifest>"); + pw.println(" </jar>"); + + } else if (packaging.equals("war")) { + + // Build a WAR + pw.println(" <war destfile=\"target/" + project.getArtifactId() + ".war\" webxml=\"src/main/webapp/WEB-INF/web.xml\">"); + pw.println(" <fileset dir=\"src/main/webapp\"/>"); + pw.println(" <lib refid=\"tuscany.jars\"/>"); + pw.println(" <lib refid=\"3rdparty.jars\"/>"); + pw.println(" <classes dir=\"target/classes\"/>"); + pw.println(" </war>"); + } + pw.println(" </target>"); + pw.println(); + + + // Generate a package target alongside the compile target + // Tuscany SCA samples use "package" as the target for webapps + pw.println(" <target name=\"package\" depends=\"compile\"/>"); + pw.println(); + + // Generate the run target + if (mainClass != null) { + pw.println(" <target name=\"run\">"); + pw.println(" <java classname=\"" + mainClass + "\" fork=\"true\">"); + pw.println(" <classpath>"); + pw.println(" <pathelement location=\"target/" + project.getArtifactId() + ".jar\"/>"); + pw.println(" <fileset refid=\"tuscany.jars\"/>"); + pw.println(" <fileset refid=\"3rdparty.jars\"/>"); + pw.println(" </classpath>"); + pw.println(" </java>"); + pw.println(" </target>"); + pw.println(); + } + + // Generate the clean target + pw.println(" <target name=\"clean\">"); + pw.println(" <delete includeemptydirs=\"true\">"); + pw.println(" <fileset dir=\"target\"/>"); + pw.println(" </delete>"); + pw.println(" </target>"); + pw.println(); + + // Generate Ant filesets representing the build dependencies + generateBuildDependencies(pw); + + pw.println("</project>"); + pw.close(); + } + + /** + * Generate Ant filesets representing the build dependencies. + * @param pw PrintWriter to write to + */ + private void generateBuildDependencies(PrintWriter pw) { + + // Determine the module dependencies + List<String> tuscanyModules = new ArrayList<String>(); + List<String> otherModules = new ArrayList<String>(); + for (Artifact artifact: (List<Artifact>)project.getRuntimeArtifacts()) { + if (artifact.getGroupId().startsWith("org.apache.tuscany.sca")) { + tuscanyModules.add(artifact.getFile().getName()); + } else { + otherModules.add(artifact.getFile().getName()); + } + } + + // Sort lists of modules, making output deterministic + Collections.sort(tuscanyModules); + Collections.sort(otherModules); + + // Generate filesets for the tuscany and 3rd party dependencies + pw.println(" <fileset id=\"tuscany.jars\" dir=\"" + pathToRootDir + "/modules\">"); + for (String name: tuscanyModules) { + pw.println(" <include name=\"" + name +"\"/>"); + } + pw.println(" </fileset>"); + pw.println(" <fileset id=\"3rdparty.jars\" dir=\"" + pathToRootDir + "/lib\">"); + for (String name: otherModules) { + pw.println(" <include name=\"" + name +"\"/>"); + } + pw.println(" </fileset>"); + pw.println(); + } + + /** + * Extract plugin execution configurations out of the Maven model. This handles + * nested configurations with a base configuration and a collection of nested + * configuration elements, for example: + * <configuration> + * <schemaFiles> + * <configuration> + * <fileName>x.wsdl</fileName> + * </configuration> + * <configuration> + * <fileName>y.wsdl</fileName> + * </configuration> + * </schemaFiles> + * <noNotification>true</noNotification> + * </configuration> + * + * @param execution Maven plugin execution model + * @return a list of maps containing the plugin configuration key value pairs + */ + private static List<Map<String, String>> pluginConfigurations(PluginExecution execution) { + List<Map<String, String>> configurations = new ArrayList<Map<String,String>>(); + Map<String, String> topConfiguration = new HashMap<String, String>(); + + Xpp3Dom dom = (Xpp3Dom)execution.getConfiguration(); + for (Xpp3Dom element: dom.getChildren()) { + if (element.getChildCount() != 0) { + // Handle nested configuration element, create a child configuration + // for each + for (Xpp3Dom childConfigurationElement: element.getChildren()) { + Map<String, String> childConfiguration = new HashMap<String, String>(); + for (Xpp3Dom childElement: childConfigurationElement.getChildren()) { + childConfiguration.put(childElement.getName(), childElement.getValue()); + } + configurations.add(childConfiguration); + } + } else { + // Handle top level key value pair element + topConfiguration.put(element.getName(), element.getValue()); + } + } + // Return the top configuration or the child configurations merged + // with the top one + if (configurations.isEmpty()) { + configurations.add(topConfiguration); + } else { + for (Map<String, String> configuration: configurations) { + configuration.putAll(topConfiguration); + } + } + return configurations; + } + + /** + * Generate Ant tasks for the pre-compilation generation plugins + * used in the Maven module. + * @param pw PrintWriter to write to + * @return list of directories containing generated source to compile + */ + private void generatePreCompileTasks(PrintWriter pw) { + String baseDir = project.getBasedir().getAbsolutePath() + '/'; + + List<Plugin> plugins = (List<Plugin>)project.getBuildPlugins(); + for (Plugin plugin: plugins) { + + // Generate Ant task equivalent to the Tuscany SDO plugin + if ("org.apache.tuscany.sdo".equals(plugin.getGroupId()) && "tuscany-sdo-plugin".equals(plugin.getArtifactId())) { + for (PluginExecution execution: (List<PluginExecution>)plugin.getExecutions()) { + for (Map<String, String> configuration: pluginConfigurations(execution)) { + + pw.println(" <java classname=\"org.apache.tuscany.sdo.generate.XSD2JavaGenerator\" fork=\"true\">"); + + // Generate the various code generation options + for (Map.Entry<String, String> element: configuration.entrySet()) { + String key = element.getKey(); + String value = element.getValue(); + if (key.equals("schemaNamespace")) { + pw.println(" <arg value=\"-schemaNamespace\"/>"); + pw.println(" <arg value=\"" + value + "\"/>"); + } + if (key.equals("javaPackage")) { + pw.println(" <arg value=\"-javaPackage\"/>"); + pw.println(" <arg value=\"" + value + "\"/>"); + } + if (key.equals("prefix")) { + pw.println(" <arg value=\"-prefix\"/>"); + pw.println(" <arg value=\"" + value + "\"/>"); + } + if (key.equals("noInterfaces") && "true".equals(value)) { + pw.println(" <arg value=\"-noInterfaces\"/>"); + } + if (key.equals("noNotification") && "true".equals(value)) { + pw.println(" <arg value=\"-noNotification\"/>"); + } + if (key.equals("noContainer") && "true".equals(value)) { + pw.println(" <arg value=\"-noContainment\"/>"); + } + if (key.equals("noUnsettable") && "true".equals(value)) { + pw.println(" <arg value=\"-noUnsettable\"/>"); + } + } + + // Generate target directory parameter + String targetDirectory = configuration.get("targetDirectory"); + if (targetDirectory == null) { + targetDirectory = "target/sdo-source"; + } else if (targetDirectory.startsWith(baseDir)) { + targetDirectory = targetDirectory.substring(baseDir.length()); + } + pw.println(" <arg value=\"-targetDirectory\"/>"); + pw.println(" <arg value=\"" + targetDirectory + "\"/>"); + + // Generate schema file parameter + String schemaFile = configuration.get("schemaFile"); + if (schemaFile == null) { + schemaFile = configuration.get("fileName"); + } + if (schemaFile != null) { + if (schemaFile.startsWith(baseDir)) { + schemaFile = schemaFile.substring(baseDir.length()); + } + pw.println(" <arg value=\"" + schemaFile + "\"/>"); + } + + pw.println(" <classpath>"); + pw.println(" <fileset refid=\"tuscany.jars\"/>"); + pw.println(" <fileset refid=\"3rdparty.jars\"/>"); + pw.println(" </classpath>"); + pw.println(" </java>"); + } + } + } + + // Generate Ant task equivalent to the Tuscany WSDL2Java plugin + else if ("org.apache.tuscany.sca".equals(plugin.getGroupId()) && "tuscany-maven-wsdl2java".equals(plugin.getArtifactId())) { + for (PluginExecution execution: (List<PluginExecution>)plugin.getExecutions()) { + for (Map<String, String> configuration: pluginConfigurations(execution)) { + + pw.println(" <java classname=\"org.apache.tuscany.tools.wsdl2java.generate.WSDL2JavaGenerator\" fork=\"true\">"); + + // Generate the various code generation options + for (Map.Entry<String, String> element: configuration.entrySet()) { + String key = element.getKey(); + String value = element.getValue(); + if (key.equals("javaPackage")) { + pw.println(" <arg value=\"-javaPackage\"/>"); + pw.println(" <arg value=\"" + value + "\"/>"); + } + } + + // Generate target directory parameter + String targetDirectory = configuration.get("targetDirectory"); + if (targetDirectory == null) { + targetDirectory = "target/wsdl2java-source"; + } else if (targetDirectory.startsWith(baseDir)) { + targetDirectory = targetDirectory.substring(baseDir.length()); + } + pw.println(" <arg value=\"-targetDirectory\"/>"); + pw.println(" <arg value=\"" + targetDirectory + "\"/>"); + + // Generate WSDL file parameter + String wsdlFile = configuration.get("wsdlFile"); + if (wsdlFile == null) { + wsdlFile = configuration.get("fileName"); + } + if (wsdlFile != null) { + if (wsdlFile.startsWith(baseDir)) { + wsdlFile = wsdlFile.substring(baseDir.length()); + } + pw.println(" <arg value=\"" + wsdlFile + "\"/>"); + } + + pw.println(" <classpath>"); + pw.println(" <fileset refid=\"tuscany.jars\"/>"); + pw.println(" <fileset refid=\"3rdparty.jars\"/>"); + pw.println(" </classpath>"); + pw.println(" </java>"); + } + } + } + } + } + + /** + * Generate license header. + * + * @param pw PrintWriter to write to + */ + private void generateLicenseHeader(PrintWriter pw) { + pw.println("<!--"); + pw.println(" * Licensed to the Apache Software Foundation (ASF) under one"); + pw.println(" * or more contributor license agreements. See the NOTICE file"); + pw.println(" * distributed with this work for additional information"); + pw.println(" * regarding copyright ownership. The ASF licenses this file"); + pw.println(" * to you under the Apache License, Version 2.0 (the"); + pw.println(" * \"License\"); you may not use this file except in compliance"); + pw.println(" * with the License. You may obtain a copy of the License at"); + pw.println(" * "); + pw.println(" * http://www.apache.org/licenses/LICENSE-2.0"); + pw.println(" * "); + pw.println(" * Unless required by applicable law or agreed to in writing,"); + pw.println(" * software distributed under the License is distributed on an"); + pw.println(" * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY"); + pw.println(" * KIND, either express or implied. See the License for the"); + pw.println(" * specific language governing permissions and limitations"); + pw.println(" * under the License."); + pw.println("-->"); + pw.println(); + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/LICENSE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/LICENSE @@ -0,0 +1,205 @@ +
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/NOTICE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/README b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/README new file mode 100644 index 0000000000..d53760029f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/README @@ -0,0 +1,46 @@ +Tuscany SCA Dependency Lister
+=============================
+
+Makes use of the extension Maven dependency support to list out all of the
+dependencis in the module where the plugin is used. The module is
+analysed and a report (dependency.txt) is written into the modules directory including
+each dependency and the path through the maven transitive dependencies that caused
+the original dependency to be included. For example, Here is a line which lists
+a a jar dependency, the phase in which it was found, the module being processed
+and he path that causes the dependency
+
+DEPENDENCY PHASE MODULE PATH TO DEPENDENCY
+jaxb-api-2.1.jar compile Apache Tuscany SCA Atom+RSS Feed Aggregator Sample Webapp tuscany-host-webapp-1.1-incubating-SNAPSHOT tuscany-host-embedded-1.1-incubating-SNAPSHOT tuscany-core-databinding-1.1-incubating-SNAPSHOT tuscany-databinding-jaxb-1.1-incubating-SNAPSHOT jaxb-api-2.1
+
+It is often convenient to further analyse these entries using the spreadsheet of your
+choice so the columns are tab separated to allow for easy conversion.
+
+The plugin can be included in a module using the following,
+
+<plugin>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-maven-dependency-lister</artifactId>
+ <version>1.1-incubating-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ </execution>
+ </executions>
+</plugin>
+
+If you include this at the top level of you project and have it run for each model you
+will get a report for each model independently. For example, in the Tuscany SCA project
+the plugin is included in the pom.xml files at the sca level under the profile
+"dependecies" so to generate a dependencies report for the Tuscany SCA project:
+
+cd sca
+mvn -o -Pdependencies -Dmaven.test.skip=true
+
+Once you have dependency.txt files in your modules
+the you favourite command line tools can be used to concatenate and sort them
+to get a full picture of the dependencies in you project, for example, with linux you
+could do,
+
+find . -name dependency.txt -exec cat '{}' >> deptotal.txt \;
diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/pom.xml new file mode 100644 index 0000000000..9d12f38e04 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/pom.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-maven-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-maven-dependency-lister</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany SCA Dependency Lister Maven Plugin</name> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-settings</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + <version>1.0</version> + </dependency> + + + </dependencies> +</project> diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/src/main/java/org/apache/tuscany/tools/sca/dependency/lister/plugin/DependencyListerMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/src/main/java/org/apache/tuscany/tools/sca/dependency/lister/plugin/DependencyListerMojo.java new file mode 100644 index 0000000000..b904ac4804 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-dependency-lister/src/main/java/org/apache/tuscany/tools/sca/dependency/lister/plugin/DependencyListerMojo.java @@ -0,0 +1,198 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.tools.sca.dependency.lister.plugin;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.maven.shared.dependency.tree.DependencyTree;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+
+/**
+ * @version $Rev: 588816 $ $Date: 2007-10-27 01:22:38 +0100 (Sat, 27 Oct 2007) $
+ * @goal execute
+ * @phase generate-sources
+ * @requiresDependencyResolution test
+ * @description List dependencies for an SCA project
+ */
+public class DependencyListerMojo extends AbstractMojo {
+ /**
+ * The project to create a build for.
+ *
+ * @parameter expression="${project}"
+ * @required
+ */
+ private MavenProject project;
+
+ /**
+ * Used for resolving artifacts
+ *
+ * @component
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
+ * Factory for creating artifact objects
+ *
+ * @component
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @component
+ */
+ private ArtifactMetadataSource artifactMetadataSource;
+
+ /**
+ * @component
+ */
+ private DependencyTreeBuilder dependencyTreeBuilder;
+
+ /**
+ * @component
+ */
+ private ArtifactCollector collector;
+
+ /**
+ * @component
+ */
+ private MavenProjectBuilder mavenProjectBuilder;
+
+ /**
+ * The local repository where the artifacts are located
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * The remote repositories where artifacts are located
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ */
+ private List remoteRepositories;
+
+ /**
+ * The current user system settings for use in Maven.
+ *
+ * @parameter expression="${settings}"
+ * @required
+ * @readonly
+ */
+ private Settings settings;
+
+
+ /**
+ * The build.xml file to generate.
+ * @parameter expression="${basedir}/target/dependency.txt"
+ */
+ private String buildFile;
+
+ public void execute() throws MojoExecutionException {
+
+ System.out.println("Analysing " + buildFile);
+
+ // Open the target build.xml file
+ File targetFile = new File(buildFile);
+ PrintWriter pw;
+ try {
+ pw = new PrintWriter(new FileOutputStream(targetFile));
+ } catch (FileNotFoundException e) {
+ System.out.println(e.toString());
+ return;
+ }
+
+ DependencyTree dependencyTree;
+
+ try
+ {
+ dependencyTree = dependencyTreeBuilder.buildDependencyTree( project, localRepository, artifactFactory,
+ artifactMetadataSource, collector );
+ }
+ catch ( DependencyTreeBuilderException e )
+ {
+ throw new MojoExecutionException( "Can't build dependency tree", e );
+ }
+
+ // processNode(dependencyTree.getRootNode(), "--", pw);
+
+ for (Artifact artifact: (List<Artifact>)project.getTestArtifacts()) {
+ pw.println( artifact.getFile().getName() + "\t" +
+ artifact.getScope() + "\t" +
+ project.getName() + "\t" +
+ findArtifactPath(dependencyTree.getRootNode(), artifact));
+ }
+
+ pw.close();
+ }
+
+ private void processNode(DependencyNode node, String indent, PrintWriter pw){
+
+ pw.println(indent + node.getArtifact().getScope() + " " + node.getArtifact().toString());
+
+ Iterator it = node.getChildren().iterator();
+ while ( it.hasNext() )
+ {
+ DependencyNode child = (DependencyNode) it.next();
+
+ processNode(child, indent + "--", pw);
+ }
+ }
+
+ private String findArtifactPath(DependencyNode node, Artifact artifact){
+ String path = null;
+
+ Iterator it = node.getChildren().iterator();
+ while ( it.hasNext() && (path == null) )
+ {
+ DependencyNode child = (DependencyNode) it.next();
+
+ if (child.getArtifact().getArtifactId().equals(artifact.getArtifactId())) {
+ path = child.getArtifact().getArtifactId() + "-" + child.getArtifact().getVersion();
+ } else {
+ path = findArtifactPath(child, artifact);
+
+ if (path != null){
+ path = child.getArtifact().getArtifactId() + "-" + child.getArtifact().getVersion() + "\t" + path;
+ }
+ }
+ }
+
+ return path;
+ }
+
+}
\ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/LICENSE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/NOTICE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/pom.xml new file mode 100644 index 0000000000..77d573b191 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/pom.xml @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-maven-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-maven-incremental-build</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany SCA Incremental Build Generator Maven Plugin</name> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-settings</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>2.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-invoker</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-compiler-api</artifactId> + <version>1.5.3</version> + </dependency> + + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-compiler-manager</artifactId> + <version>1.5.3</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-compiler-javac</artifactId> + <version>1.5.3</version> + <scope>runtime</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>2.5</version> + <configuration> + <goalPrefix>incremental</goalPrefix> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java new file mode 100644 index 0000000000..3a6870732b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java @@ -0,0 +1,415 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.tools.incremental.build.plugin; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; +import org.apache.maven.shared.invoker.DefaultInvocationRequest; +import org.apache.maven.shared.invoker.InvocationResult; +import org.apache.maven.shared.invoker.Invoker; +import org.apache.maven.shared.invoker.MavenInvocationException; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.cli.CommandLineException; + +/** + * @version $Rev$ $Date$ + * @goal build + * @phase validate + * @requiresDependencyResolution test + * @description Incrementally build project modules that depend on modified modules. + */ +public class IncrementalBuildMojo extends AbstractMojo { + + /** + * Keep track of modified projects. + */ + private static Set<String> modifiedProjectIDs = new HashSet<String>(); + + /** + * The current user system settings for use in Maven. + * + * @parameter expression="${settings}" + * @required + * @readonly + */ + private Settings settings; + + /** + * Used to invoke Maven builds. + * + * @component + */ + private Invoker invoker; + + /** + * The target directory of the compiler if fork is true. + * + * @parameter expression="${project.build.directory}" + * @required + * @readonly + */ + private File buildDirectory; + + /** + * The project to create a build for. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + private File outputFile; + + public void execute() throws MojoExecutionException { + String projectID = id(project); + outputFile = getOutputFile(); + + File testMarkerFile = new File(project.getBasedir().getPath() + "/.test"); + + List<String> goals = new ArrayList<String>(); + String type = project.getArtifact().getType(); + if ("pom".equals(type)) { + + // Always install pom modules + goals.add("install"); + + } else { + + // Check if anything has changed in the project + boolean changed = false; + boolean testChanged = false; + boolean testFailed = false; + if (new File(project.getBasedir().getPath() + "/.modified").exists()) { + getLog().info("Found .modified marker file."); + changed = true; + } else { + changed = areSourcesStale() || areResourcesStale() || isPOMStale(); + } + if (changed) { + modifiedProjectIDs.add(projectID); + } else { + testChanged = areTestSourcesStale() || areTestResourcesStale(); + } + + // Check if a project has compile dependencies on the modified projects + // and will need to be recompiled, or has runtime or test dependencies + // on the modified projects and needs to be retested + if (changed) { + goals.add("clean"); + goals.add("install"); + getLog().info("Project " + projectID + " has changed and will be recompiled."); + + } else { + for (Artifact artifact : (List<Artifact>)project.getCompileArtifacts()) { + String artifactID = id(artifact); + if (modifiedProjectIDs.contains(artifactID)) { + getLog().info("Project " + projectID + " depends on modified project " + artifactID + " and will be recompiled."); + goals.add("clean"); + goals.add("install"); + break; + } + } + + if (goals.isEmpty()) { + List<Artifact> artifacts = new ArrayList<Artifact>(); + artifacts.addAll(project.getRuntimeArtifacts()); + artifacts.addAll(project.getTestArtifacts()); + for (Artifact artifact : artifacts) { + String artifactID = id(artifact); + if (modifiedProjectIDs.contains(artifactID)) { + getLog().info("Project " + projectID + " depends on modified project " + artifactID + " and will be retested."); + goals.add("test"); + break; + } + } + } + } + + if (testChanged && goals.isEmpty()) { + getLog().info("Project " + projectID + " has changed and will be retested."); + goals.add("test"); + } + + if (goals.isEmpty()) { + if (testMarkerFile.exists()) { + testFailed = true; + getLog().info("Project " + projectID + " contains failed tests and will be retested."); + goals.add("test"); + } + } + } + + // Invoke Maven with the necessary goals + if (!goals.isEmpty()) { + DefaultInvocationRequest request = new DefaultInvocationRequest(); + request.setGoals(goals); + // FIXME: The maven invoker doesn't handle the directory names with spaces + // request.setLocalRepositoryDirectory(new File(localRepository.getBasedir())); + request.setInteractive(false); + request.setShowErrors(false); + request.setRecursive(false); + // request.setDebug(true); + request.setOffline(settings.isOffline()); + request.setBaseDirectory(project.getBasedir()); + request.setPomFile(project.getFile()); + + boolean success = false; + try { + try { + InvocationResult result = invoker.execute(request); + + CommandLineException cle = result.getExecutionException(); + if (cle != null) { + throw new MojoExecutionException(cle.getMessage(), cle); + } + + int ec = result.getExitCode(); + if (ec != 0) { + throw new MojoExecutionException("Maven invocation exit code: " + ec); + } + + success = true; + + + + } catch (MavenInvocationException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } finally { + + // Create or delete a .test marker file to keep track of the latest + // test result status and trigger testing again next time the build + // is run + if (!success) { + try { + if (!testMarkerFile.exists()) { + testMarkerFile.createNewFile(); + } + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } else { + if (testMarkerFile.exists()) { + testMarkerFile.delete(); + } + } + } + } else { + getLog().info("The project is up-to-date. No build is required."); + } + } + + private File getOutputFile() { + File basedir = buildDirectory; + String finalName = project.getBuild().getFinalName(); + String classifier = project.getArtifact().getClassifier(); + if (classifier == null) { + classifier = ""; + } else if (classifier.trim().length() > 0 && !classifier.startsWith("-")) { + classifier = "-" + classifier; + } + + String pkg = project.getPackaging(); + if ("maven-plugin".equals(pkg)) { + pkg = "jar"; + } + return new File(basedir, finalName + classifier + "." + pkg); + } + + /** + * Test if any of the resources are stale + * @param resources + * @param outputDirectory + * @return + * @throws MojoExecutionException + */ + private boolean areStale(List<Resource> resources, String outputDirectory) throws MojoExecutionException { + + for (Resource resource: resources) { + + File resourceDirectory = new File(resource.getDirectory()); + if (!resourceDirectory.exists()) { + continue; + } + + DirectoryScanner scanner = new DirectoryScanner(); + + scanner.setBasedir(resource.getDirectory()); + if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) { + scanner.setIncludes((String[])resource.getIncludes().toArray(new String[]{})); + } else { + scanner.setIncludes(new String[]{"**/**"}); + } + if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) { + scanner.setExcludes((String[])resource.getExcludes().toArray(new String[]{})); + } + + scanner.addDefaultExcludes(); + scanner.scan(); + + List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles()); + String targetPath = resource.getTargetPath(); + for (String source: includedFiles) { + String target; + if (source.endsWith(".java")) { + target = source.substring(0, source.length() - 5) + ".class"; + } else { + target = source; + } + + String destination; + if (targetPath != null) { + destination = targetPath + "/" + target; + } else { + destination = target; + } + + File sourceFile = new File(resource.getDirectory(), source); + File destinationFile = new File(outputDirectory, destination); + + if (!destinationFile.exists()) { + getLog().info("Source file " + sourceFile + "."); + getLog().info("Target file " + destinationFile + " could not be found."); + return true; + } else { + if (sourceFile.lastModified() > destinationFile.lastModified()) { + getLog().info("Source file " + sourceFile + " has changed."); + getLog().info("Target file " + destinationFile + " is stale."); + return true; + } else if (sourceFile.lastModified() > outputFile.lastModified()) { + getLog().info("Source file " + sourceFile + " has changed."); + getLog().info("Target build output file " + outputFile + " is stale."); + return true; + } else if (outputFile.lastModified() == 0) { + getLog().info("Target build output file " + outputFile + " could not be found."); + return true; + } + } + } + } + return false; + } + + /** + * Test if the POM resource is stale. + * + * @return + */ + private boolean isPOMStale() { + File pom = project.getFile(); + if (pom.lastModified() > outputFile.lastModified()) { + getLog().info("File " + pom + " has changed."); + getLog().info("Target build output file " + pom + " is stale."); + return true; + } else if (outputFile.lastModified() == 0) { + getLog().info("Target build output file " + outputFile + " could not be found."); + return true; + } else { + return false; + } + } + + /** + * Test if the project resources are stale. + * + * @return + * @throws MojoExecutionException + */ + private boolean areResourcesStale() throws MojoExecutionException { + return areStale(project.getResources(), project.getBuild().getOutputDirectory()); + } + + /** + * Test if the project sources are stale. + * + * @return + * @throws MojoExecutionException + */ + private boolean areSourcesStale() throws MojoExecutionException { + List<Resource> resources = new ArrayList<Resource>(); + for (String root: (List<String>)project.getCompileSourceRoots()) { + if (new File(root).exists()) { + Resource resource = new Resource(); + resource.setDirectory(root); + resource.addInclude("*.java"); + resources.add(resource); + } + } + return areStale(resources, project.getBuild().getOutputDirectory()); + } + + /** + * Tests if the project test resources are stale. + * + * @return + * @throws MojoExecutionException + */ + private boolean areTestResourcesStale() throws MojoExecutionException { + return areStale(project.getTestResources(), project.getBuild().getTestOutputDirectory()); + } + + /** + * Tests if the project test sources are stale. + * + * @return + * @throws MojoExecutionException + */ + private boolean areTestSourcesStale() throws MojoExecutionException { + List<Resource> resources = new ArrayList<Resource>(); + for (String root: (List<String>)project.getTestCompileSourceRoots()) { + if (new File(root).exists()) { + Resource resource = new Resource(); + resource.setDirectory(root); + resources.add(resource); + } + } + return areStale(resources, project.getBuild().getTestOutputDirectory()); + } + + /** + * Returns the qualified id of a Maven artifact . + * @param p a Maven artifact + * @return a qualified id + */ + private static String id(Artifact a) { + return a.getGroupId() + ':' + a.getArtifactId(); + } + + /** + * Returns the qualified id of a Maven project. + * @param p a Maven project + * @return a qualified id + */ + private static String id(MavenProject p) { + return p.getGroupId() + ':' + p.getArtifactId(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/LICENSE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/NOTICE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/pom.xml new file mode 100644 index 0000000000..25b507db58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-maven-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-maven-java2wsdl</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany SCA Java2WSDL Maven Plugin</name> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-java2wsdl</artifactId> + <version>1.5.2-SNAPSHOT</version> + </dependency> + </dependencies> +</project> diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/plugin/Java2WSDLGeneratorMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/plugin/Java2WSDLGeneratorMojo.java new file mode 100644 index 0000000000..620e32a6fd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/plugin/Java2WSDLGeneratorMojo.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.tools.java2wsdl.plugin; + +import java.util.Hashtable; +import java.util.Map; + +import org.apache.axis2.description.java2wsdl.Java2WSDLConstants; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.tuscany.tools.java2wsdl.generate.Java2WSDLGeneratorFactory; +import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOption; + +/** + * @version $Rev$ $Date$ + * @goal generate + * @phase generate-sources + * @description Generate WSDL from a given Java class / interface + */ +public class Java2WSDLGeneratorMojo extends AbstractMojo +{ + + /** + * The name of the class for which the WSDL must be generated + * @parameter + * + */ + private String sourceClassName; + + /** + * The location where the WSDLs should be generated into + * @parameter expression="${project.build.directory}\\java2wsdl-wsdl" + */ + private String targetLocation; + + /** + * The name of the WSDL file + * @parameter + */ + private String wsdlFilename; + + + /** + * Classpaths to be included + * @parameter + * + */ + String[] classpaths; + + /** + * The name of the service + * @parameter + */ + private String serviceName; + + /** + * The binding style for the service + * @parameter + */ + private String bindingStyle; + + /** + * The binding use option + * @parameter + */ + private String bindingUse; + + /** + * The soap address + * @parameter + */ + private String soapAddress; + + public void execute() throws MojoExecutionException + { + try + { + Java2WSDLGeneratorFactory.getInstance().createGenerator().generateWSDL(createOptionsMap ()); + } + catch ( Exception e ) + { + throw new MojoExecutionException("Exception in Java2WSDL Maven Plugin ", e); + } + } + + protected Map createOptionsMap() + { + Map optionsMap = new Hashtable(); + + optionsMap.put(Java2WSDLConstants.CLASSNAME_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.CLASSNAME_OPTION, new String[]{sourceClassName})); + + if ( targetLocation != null ) + { + optionsMap.put(Java2WSDLConstants.OUTPUT_LOCATION_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.OUTPUT_LOCATION_OPTION, new String[]{targetLocation})); + } + + if ( wsdlFilename != null ) + { + optionsMap.put(Java2WSDLConstants.OUTPUT_FILENAME_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.OUTPUT_FILENAME_OPTION, new String[]{wsdlFilename})); + } + + if ( classpaths != null && classpaths.length > 0 ) + { + optionsMap.put(Java2WSDLConstants.CLASSPATH_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.CLASSPATH_OPTION, classpaths)); + } + + if ( serviceName != null ) + { + optionsMap.put(Java2WSDLConstants.SERVICE_NAME_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.SERVICE_NAME_OPTION, new String[]{serviceName})); + } + + if ( bindingStyle != null ) + { + optionsMap.put(Java2WSDLConstants.STYLE_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.STYLE_OPTION, new String[]{bindingStyle})); + } + + if ( bindingUse != null ) + { + optionsMap.put(Java2WSDLConstants.USE_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.USE_OPTION, new String[]{bindingUse})); + } + + if ( soapAddress != null ) + { + optionsMap.put(Java2WSDLConstants.LOCATION_OPTION, + new Java2WSDLCommandLineOption(Java2WSDLConstants.LOCATION_OPTION, new String[]{soapAddress})); + } + + return optionsMap; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/LICENSE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/LICENSE @@ -0,0 +1,205 @@ +
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/NOTICE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/pom.xml new file mode 100644 index 0000000000..258e67c1fd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/pom.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-maven-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-maven-osgi-junit</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany SCA OSGi JUnit Maven Plugin</name> + + <dependencies> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-launcher-osgi</artifactId> + <version>1.5.2-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>compile</scope> + </dependency> + + </dependencies> +</project> diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/src/main/java/org/apache/tuscany/tools/sca/osgi/junit/plugin/OSGiJUnitMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/src/main/java/org/apache/tuscany/tools/sca/osgi/junit/plugin/OSGiJUnitMojo.java new file mode 100644 index 0000000000..a2251a6a2a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-osgi-junit/src/main/java/org/apache/tuscany/tools/sca/osgi/junit/plugin/OSGiJUnitMojo.java @@ -0,0 +1,284 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.tools.sca.osgi.junit.plugin; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import junit.framework.Assert; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.apache.tuscany.sca.node.osgi.launcher.FelixOSGiHost; +import org.apache.tuscany.sca.node.osgi.launcher.LauncherBundleActivator; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + +/** + * @version $Rev$ $Date$ + * @goal test + * @phase integration-test + * @requiresDependencyResolution test + * @description Run the unit test with OSGi + */ +public class OSGiJUnitMojo extends AbstractMojo { + /** + * The project to create a build for. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * The basedir of the project. + * + * @parameter expression="${basedir}" + * @required @readonly + */ + protected File basedir; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}" + * @required + * @readonly + */ + protected org.apache.maven.artifact.factory.ArtifactFactory factory; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}" + * @required + * @readonly + */ + protected org.apache.maven.artifact.resolver.ArtifactResolver resolver; + + /** + * Location of the local repository. + * + * @parameter expression="${localRepository}" + * @readonly + * @required + */ + protected org.apache.maven.artifact.repository.ArtifactRepository local; + + /** + * List of Remote Repositories used by the resolver + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @readonly + * @required + */ + protected java.util.List remoteRepos; + + /** + * @parameter + */ + protected String osgiRuntime; + + protected Artifact getArtifact(String groupId, String artifactId) throws MojoExecutionException { + Artifact artifact; + VersionRange vr; + try { + vr = VersionRange.createFromVersionSpec(project.getVersion()); + } catch (InvalidVersionSpecificationException e1) { + vr = VersionRange.createFromVersion(project.getVersion()); + } + artifact = factory.createDependencyArtifact(groupId, artifactId, vr, "jar", null, Artifact.SCOPE_TEST); + + try { + resolver.resolve(artifact, remoteRepos, local); + } catch (ArtifactResolutionException e) { + throw new MojoExecutionException("Unable to resolve artifact.", e); + } catch (ArtifactNotFoundException e) { + throw new MojoExecutionException("Unable to find artifact.", e); + } + + return artifact; + } + + public void execute() throws MojoExecutionException { + if (project.getPackaging().equals("pom")) { + return; + } + + Log log = getLog(); + List<URL> jarFiles = new ArrayList<URL>(); + for (Object o : project.getArtifacts()) { + Artifact a = (Artifact)o; + 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 + */ + String aid = "equinox".equals(osgiRuntime) ? "tuscany-extensibility-equinox" : "tuscany-extensibility-osgi"; + Artifact ext = getArtifact("org.apache.tuscany.sca", aid); + try { + URL url = ext.getFile().toURI().toURL(); + if (!jarFiles.contains(url)) { + if (log.isDebugEnabled()) { + log.debug("Adding: " + ext); + } + jarFiles.add(url); + } + } catch (MalformedURLException e) { + getLog().error(e); + } + + // String home = new File(basedir, "target/tuscany").toString(); + // System.setProperty("TUSCANY_HOME", home); + // getLog().info(home); + try { + FelixOSGiHost host = new FelixOSGiHost(); + host.setActivator(new LauncherBundleActivator(jarFiles)); + BundleContext context = host.start(); + + for (Bundle b : context.getBundles()) { + if (getLog().isDebugEnabled()) { + getLog().debug(LauncherBundleActivator.toString(b, false)); + } + } + + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + URL[] urls = + new URL[] {new File(project.getBuild().getOutputDirectory()).toURI().toURL(), + new File(project.getBuild().getTestOutputDirectory()).toURI().toURL()}; + + URLClassLoader cl = new URLClassLoader(urls, tccl); + Thread.currentThread().setContextClassLoader(cl); + try { + runAllTestsFromDirs(cl, project.getBuild().getTestOutputDirectory()); + } finally { + Thread.currentThread().setContextClassLoader(tccl); + } + host.stop(); + } catch (Throwable e) { + throw new MojoExecutionException(e.getMessage(), e); + } + // finally { + // System.clearProperty("TUSCANY_HOME"); + // } + + } + + public void getTestCases(File dir, String prefix, HashSet<String> testCaseSet) { + File[] files = dir.listFiles(); + for (File file : files) { + if (file.isDirectory()) { + String newPrefix = prefix == null ? file.getName() : prefix + "." + file.getName(); + getTestCases(file, newPrefix, testCaseSet); + } else if (file.getName().endsWith("TestCase.class")) { + String name = file.getName(); + name = name.substring(0, name.length() - 6); // remove .class + name = (prefix == null) ? name : prefix + "." + name; + + testCaseSet.add(name); + } + } + } + + public void runAllTestsFromDirs(ClassLoader testClassLoader, String testDir) throws Exception { + + int failures = 0; + HashSet<String> testCaseSet = new HashSet<String>(); + getTestCases(new File(testDir), null, testCaseSet); + for (String className : testCaseSet) { + Class testClass = testClassLoader.loadClass(className); + failures += runTestCase(testClassLoader, testClass); + } + + Assert.assertEquals(0, failures); + + } + + /** + * Use java reflection to call JUNIT as the JUNIT might be in the bundles + * @param testClassLoader + * @param testClass + * @return + * @throws Exception + */ + public int runTestCase(ClassLoader testClassLoader, Class testClass) throws Exception { + + if (testClass.getName().endsWith("TestCase")) { + getLog().info("Running: " + testClass.getName()); + Class coreClass = Class.forName("org.junit.runner.JUnitCore", true, testClassLoader); + Object core = coreClass.newInstance(); + Class reqClass = Class.forName("org.junit.runner.Request", true, testClassLoader); + Method aClass = reqClass.getMethod("aClass", Class.class); + Object req = aClass.invoke(null, testClass); + Method run = coreClass.getMethod("run", reqClass); + Object result = run.invoke(core, req); + Object runs = result.getClass().getMethod("getRunCount").invoke(result); + Object ignores = result.getClass().getMethod("getIgnoreCount").invoke(result); + List failureList = (List)result.getClass().getMethod("getFailures").invoke(result); + + int failures = 0, errors = 0; + Class errorClass = Class.forName("junit.framework.AssertionFailedError", true, testClassLoader); + for (Object f : failureList) { + Object ex = f.getClass().getMethod("getException").invoke(f); + if (errorClass.isInstance(ex)) { + failures++; + } else { + errors++; + } + getLog().error((Throwable)ex); + } + + getLog().info("Test Runs: " + runs + + ", Failures: " + + failures + + ", Errors: " + + errors + + ", Ignores: " + + ignores); + + return failureList.size(); + + } + return 0; + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/pom.xml new file mode 100644 index 0000000000..de4faa19df --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/pom.xml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-maven-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-maven-bundle-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany SCA Maven OSGi Bundle Plugin</name> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-settings</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>2.0.7</version> + </dependency> + + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + <version>1.1</version> + </dependency> + + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>1.4.3</version> + </dependency> + + + </dependencies> +</project> diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.java new file mode 100644 index 0000000000..5fbd3008d2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleMojo.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.tools.sca.tuscany.bundle.plugin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.Manifest; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; + +/** + * @version $Rev$ $Date$ + * @goal build + * @phase process-sources + * @requiresDependencyResolution test + * @description Build a virtual bundle for 3rd party dependencies + */ +public class LibraryBundleMojo extends AbstractMojo { + /** + * The project to create a build for. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * The basedir of the project. + * + * @parameter expression="${basedir}" + * @required @readonly + */ + protected File basedir; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}" + * @required + * @readonly + */ + protected org.apache.maven.artifact.factory.ArtifactFactory factory; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}" + * @required + * @readonly + */ + protected org.apache.maven.artifact.resolver.ArtifactResolver resolver; + + /** + * Location of the local repository. + * + * @parameter expression="${localRepository}" + * @readonly + * @required + */ + protected org.apache.maven.artifact.repository.ArtifactRepository local; + + /** + * List of Remote Repositories used by the resolver + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @readonly + * @required + */ + protected java.util.List remoteRepos; + + /** + * @parameter + */ + protected boolean copyJars = false; + + public void execute() throws MojoExecutionException { + if (project.getPackaging().equals("pom")) { + return; + } + + Log log = getLog(); + List<File> jarFiles = new ArrayList<File>(); + for (Object o : project.getArtifacts()) { + Artifact a = (Artifact)o; + if (!(Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) { + if (log.isDebugEnabled()) { + log.debug("Skipping artifact: " + a); + } + continue; + } + if (log.isDebugEnabled()) { + log.debug("Artifact: " + a); + } + String bundleName = null; + try { + bundleName = LibraryBundleUtil.getBundleName(a.getFile()); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + if (bundleName == null) { + if (log.isDebugEnabled()) { + log.debug("Adding non-OSGi jar: " + a); + } + jarFiles.add(a.getFile()); + } + } + + try { + String version = project.getVersion(); + if (version.endsWith(Artifact.SNAPSHOT_VERSION)) { + version = version.substring(0, version.length() - Artifact.SNAPSHOT_VERSION.length() - 1); + } + + Manifest mf = LibraryBundleUtil.libraryManifest(jarFiles, project.getName(), version, copyJars); + 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); + mf.write(fos); + fos.close(); + + if (copyJars) { + 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); + int len = 0; + while (len > 0) { + len = in.read(buf); + if (len > 0) { + out.write(buf, 0, len); + } + } + in.close(); + out.close(); + } + } + } catch (Exception e) { + throw new MojoExecutionException(e.getMessage(), e); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.java new file mode 100644 index 0000000000..ed4ac63533 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/LibraryBundleUtil.java @@ -0,0 +1,244 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.tools.sca.tuscany.bundle.plugin; + +import static org.osgi.framework.Constants.BUNDLE_CLASSPATH; +import static org.osgi.framework.Constants.BUNDLE_MANIFESTVERSION; +import static org.osgi.framework.Constants.BUNDLE_NAME; +import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME; +import static org.osgi.framework.Constants.BUNDLE_VERSION; +import static org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE; +import static org.osgi.framework.Constants.EXPORT_PACKAGE; +import static org.osgi.framework.Constants.IMPORT_PACKAGE; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import org.osgi.framework.Bundle; + +/** + * Common functions and constants used by the admin components. + * + * @version $Rev$ $Date$ + */ +public final class LibraryBundleUtil { + + private static final String LAUNCHER_EQUINOX_LIBRARIES = "org.apache.tuscany.sca.node.launcher.equinox.libraries"; + + static File file(URL url) { + if (url == null || !url.getProtocol().equals("file")) { + return null; + } else { + String filename = url.getFile().replace('/', File.separatorChar); + int pos = 0; + while ((pos = filename.indexOf('%', pos)) >= 0) { + if (pos + 2 < filename.length()) { + String hexStr = filename.substring(pos + 1, pos + 3); + char ch = (char)Integer.parseInt(hexStr, 16); + filename = filename.substring(0, pos) + ch + filename.substring(pos + 3); + } + } + return new File(filename); + } + } + + static Pattern pattern = Pattern.compile("-([0-9.]+)"); + + private static String version(String jarFile) { + Matcher matcher = pattern.matcher(jarFile); + String version = "1.0.0"; + if (matcher.find()) { + version = matcher.group(); + if (version.endsWith(".")) { + version = version.substring(1, version.length() - 1); + } else { + version = version.substring(1); + } + } + return version; + } + + private static void addPackages(File jarFile, Set<String> packages) throws IOException { + String version = ";version=" + version(jarFile.getPath()); + ZipInputStream is = new ZipInputStream(new FileInputStream(jarFile)); + ZipEntry entry; + while ((entry = is.getNextEntry()) != null) { + String entryName = entry.getName(); + if (!entry.isDirectory() && entryName != null + && entryName.length() > 0 + && !entryName.startsWith(".") + && entryName.endsWith(".class") // Exclude resources from Export-Package + && entryName.lastIndexOf("/") > 0) { + String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/', '.') + version; + packages.add(pkg); + } + } + is.close(); + } + + static Manifest libraryManifest(List<File> jarFiles, String name, String version, boolean copyJars) + throws IllegalStateException { + try { + + // List exported packages and bundle classpath entries + StringBuffer classpath = new StringBuffer(); + StringBuffer exports = new StringBuffer(); + StringBuffer imports = new StringBuffer(); + Set<String> packages = new HashSet<String>(); + for (File jarFile : jarFiles) { + addPackages(jarFile, packages); + if (copyJars) { + classpath.append("\"lib/"); + classpath.append(jarFile.getName()); + classpath.append("\","); + } else { + classpath.append("\"external:"); + classpath.append(jarFile.getPath().replace(File.separatorChar, '/')); + classpath.append("\","); + } + } + + Set<String> importPackages = new HashSet<String>(); + for (String pkg : packages) { + exports.append(pkg); + exports.append(','); + + String importPackage = pkg; + int index = pkg.indexOf(';'); + if (index != -1) { + importPackage = pkg.substring(0, index); + } + if (!importPackages.contains(importPackage)) { + imports.append(importPackage); + imports.append(','); + importPackages.add(importPackage); + } + } + + // Create a manifest + Manifest manifest = new Manifest(); + Attributes attributes = manifest.getMainAttributes(); + attributes.putValue("Manifest-Version", "1.0"); + attributes.putValue(BUNDLE_MANIFESTVERSION, "2"); + attributes.putValue(BUNDLE_SYMBOLICNAME, LAUNCHER_EQUINOX_LIBRARIES); + attributes.putValue(BUNDLE_NAME, name); + attributes.putValue(BUNDLE_VERSION, version); + attributes.putValue(EXPORT_PACKAGE, exports.substring(0, exports.length() - 1)); + attributes.putValue(IMPORT_PACKAGE, imports.substring(0, imports.length() - 1)); + attributes.putValue(BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() - 1)); + attributes.putValue(DYNAMICIMPORT_PACKAGE, "*"); + + return manifest; + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + static String dump(Manifest mf) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + mf.write(bos); + return new String(bos.toByteArray()); + } + + static byte[] generateBundle(Manifest mf) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + JarOutputStream jos = new JarOutputStream(bos, mf); + jos.close(); + return bos.toByteArray(); + } + + /** + * Returns the name of a bundle, or null if the given file is not a bundle. + * + * @param file + * @return + * @throws IOException + */ + static String getBundleName(File file) throws IOException { + if (!file.exists()) { + return null; + } + String bundleName = null; + if (file.isDirectory()) { + File mf = new File(file, "META-INF/MANIFEST.MF"); + if (mf.isFile()) { + Manifest manifest = new Manifest(new FileInputStream(mf)); + bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + } + } else { + JarFile jar = new JarFile(file, false); + Manifest manifest = jar.getManifest(); + bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + jar.close(); + } + if (bundleName == null) { + return bundleName; + } + int sc = bundleName.indexOf(';'); + if (sc != -1) { + bundleName = bundleName.substring(0, sc); + } + return bundleName; + } + + public static String string(Bundle b, boolean verbose) { + StringBuffer sb = new StringBuffer(); + sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName()); + int s = b.getState(); + if ((s & Bundle.UNINSTALLED) != 0) { + sb.append(" UNINSTALLED"); + } + if ((s & Bundle.INSTALLED) != 0) { + sb.append(" INSTALLED"); + } + if ((s & Bundle.RESOLVED) != 0) { + sb.append(" RESOLVED"); + } + if ((s & Bundle.STARTING) != 0) { + sb.append(" STARTING"); + } + if ((s & Bundle.STOPPING) != 0) { + sb.append(" STOPPING"); + } + if ((s & Bundle.ACTIVE) != 0) { + sb.append(" ACTIVE"); + } + + if (verbose) { + sb.append(" ").append(b.getLocation()); + sb.append(" ").append(b.getHeaders()); + } + return sb.toString(); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java new file mode 100644 index 0000000000..79b0db4223 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java @@ -0,0 +1,505 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.tools.sca.tuscany.bundle.plugin; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.JarInputStream; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; + +import org.apache.felix.bundleplugin.BundleAllPlugin; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.versioning.OverConstrainedVersionException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.apache.maven.shared.dependency.tree.DependencyTree; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.apache.maven.shared.osgi.Maven2OsgiConverter; +import org.osgi.framework.Version; + +import aQute.lib.header.OSGiHeader; + +/** + * @version $$ + * @goal execute + * @phase compile + * @requiresDependencyResolution test + * @description Generate versioned OSGi bundles corresponding to Tuscany modules and all 3rd party dependencies + */ +public class TuscanyBundlePluginMojo extends BundleAllPlugin { + /** + * The maven project + * + * @parameter expression="${project}" + * @required + */ + private MavenProject project; + + /** + * Directory containing pom. + * + * @parameter expression="${basedir}" + * @required + */ + private File baseDir; + + /** + * Build directory for project + * + * @parameter expression="${project.build.directory}" + * @required + */ + private String buildDirectory; + + /** + * Output directory where bundles are generated. + * + * @parameter expression="${project.build.outputDirectory}" + * @required + */ + private File outputDirectory; + + /** + * Artifact resolver + * + * @component + */ + private ArtifactResolver artifactResolver; + + /** + * Artifact factory + * + * @component + */ + private ArtifactFactory artifactFactory; + + /** + * @component + */ + private ArtifactMetadataSource artifactMetadataSource; + + /** + * Dependency tree builder + * + * @component + */ + private DependencyTreeBuilder dependencyTreeBuilder; + + /** + * @component + */ + private ArtifactCollector collector; + + /** + * @component + */ + private MavenProjectBuilder mavenProjectBuilder; + + /** + * The local repository + * + * @parameter expression="${localRepository}" + * @required + */ + private ArtifactRepository localRepository; + + /** + * The remote repositories + * + * @parameter expression="${project.remoteArtifactRepositories}" + */ + private List remoteRepositories; + + /** + * @component + */ + private Maven2OsgiConverter maven2OsgiConverter; + + private static final HashSet<String> dependenciesToIgnore = new HashSet<String>(); + private static final HashSet<String> importDirectives = new HashSet<String>(); + private static final HashSet<String> exportDirectives = new HashSet<String>(); + private static final Hashtable<String, String> privatePackages = new Hashtable<String, String>(); + private static final Hashtable<String, String> dynamicImports = new Hashtable<String, String>(); + + static { + importDirectives.add("resolution"); + + exportDirectives.add("uses"); + exportDirectives.add("mandatory"); + exportDirectives.add("include"); + exportDirectives.add("exclude"); + + dependenciesToIgnore.add("xml-apis:xml-apis"); + dependenciesToIgnore.add("stax:stax-api"); + + + // Comma separated list of packages + privatePackages.put("org.apache.woden:woden", "javax.xml.namespace"); + privatePackages.put("org.apache.xmlbeans:xmlbeans", "org.w3c.dom"); + privatePackages.put("org.apache.axis2:axis2-adb", "org.apache.axis2.util"); + privatePackages.put("org.apache.axis2:addressing", "org.apache.axis2.addressing"); + privatePackages.put("org.apache.axis2:axis2-kernel", "org.apache.axis2.wsdl"); + privatePackages.put("org.apache.bsf:bsf-all", "org.mozilla.javascript"); + privatePackages.put("org.apache.axis2:axis2-codegen", "org.apache.axis2.wsdl,org.apache.axis2.wsdl.util"); + + dynamicImports.put("org.apache.ws.commons.axiom:axiom-api", "org.apache.axiom.om.impl.*,org.apache.axiom.soap.impl.*"); + dynamicImports.put("org.apache.bsf:bsf-all", "org.mozilla.*"); + dynamicImports.put("org.apache.santuario:xmlsec", "org.apache.ws.security.*"); + } + + + @SuppressWarnings("unchecked") + public void execute() throws MojoExecutionException { + try { + + setBasedir(baseDir); + setBuildDirectory(buildDirectory); + setOutputDirectory(outputDirectory); + setMaven2OsgiConverter(maven2OsgiConverter); + try { + Field importField = this.getClass().getSuperclass().getDeclaredField("wrapImportPackage"); + importField.setAccessible(true); + importField.set(this, "*;resolution:=optional"); + } catch (Exception e2) { + e2.printStackTrace(); + getLog().error("Could not set import instructions"); + } + + + DependencyTree dependencyTree = dependencyTreeBuilder.buildDependencyTree(project, + localRepository, artifactFactory, + artifactMetadataSource, collector ); + + Hashtable<String, String> duplicateWarnings = new Hashtable<String, String>(); + Hashtable<String, Artifact> artifactsToBundle = new Hashtable<String, Artifact>(); + + for (Object a : dependencyTree.getArtifacts()) { + Artifact artifact = (Artifact)a; + + if (project.getArtifactId().equals(artifact.getArtifactId()) && project.getGroupId().equals(artifact.getGroupId())) + continue; + + if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())||Artifact.SCOPE_TEST.equals(artifact.getScope())) + continue; + + String id = artifact.getGroupId() + ":" + artifact.getArtifactId(); + if (dependenciesToIgnore.contains(id)) + continue; + + Artifact old = artifactsToBundle.get(id); + if (old != null && !old.getVersion().equals(artifact.getVersion())) { + String oldVersion = old.getVersion(); + String thisVersion = artifact.getVersion(); + if (!thisVersion.equals(duplicateWarnings.get(oldVersion))&&!oldVersion.equals(duplicateWarnings.get(thisVersion))) { + getLog().warn("Multiple versions of artifacts : " + old + ", " + artifact); + duplicateWarnings.put(oldVersion, thisVersion); + } + + } + + VersionRange versionRange = artifact.getVersionRange(); + if (versionRange == null) + versionRange = VersionRange.createFromVersion(artifact.getVersion()); + + Artifact dependencyArtifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(), + artifact.getArtifactId(), + versionRange, + artifact.getType(), + artifact.getClassifier(), + artifact.getScope()); + + try { + if (old != null && old.getSelectedVersion().compareTo(artifact.getSelectedVersion()) >= 0) + continue; + else + artifactsToBundle.remove(id); + } catch (OverConstrainedVersionException e1) { + getLog().warn("Could not process maven version for artifact " + artifact); + continue; + } + + try { + artifactResolver.resolve(dependencyArtifact, remoteRepositories, localRepository); + } catch (ArtifactResolutionException e) { + getLog().warn("Artifact " + artifact + " could not be resolved."); + } catch (ArtifactNotFoundException e) { + getLog().warn("Artifact " + artifact + " could not be found."); + } + + artifact.setFile(dependencyArtifact.getFile()); + + artifactsToBundle.put(id, artifact); + + } + + bundleArtifacts(artifactsToBundle.values()); + + + } catch (DependencyTreeBuilderException e) { + throw new MojoExecutionException("Could not build dependency tree", e); + } catch (ProjectBuildingException e) { + throw new MojoExecutionException("Could not build project for artifact", e); + } catch (InvalidDependencyVersionException e) { + throw new MojoExecutionException("Invalid dependency version", e); + } catch (IOException e) { + throw new MojoExecutionException("Could not build bundle manifest", e); + } + } + + + private void bundleArtifacts(Collection<Artifact> artifacts) throws ProjectBuildingException, + InvalidDependencyVersionException, MojoExecutionException, IOException { + + for (Artifact artifact : artifacts) { + + artifact.setFile(getFile( artifact )); + + MavenProject bundleProject; + try { + bundleProject = + mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true); + } catch (Exception e) { + getLog().error(e); + continue; + } + bundleProject.setArtifact(artifact); + + if ( bundleProject.getDependencyArtifacts() == null ) { + bundleProject.setDependencyArtifacts(bundleProject.createArtifacts(artifactFactory, null, null ) ); + } + + File outputFile = getOutputFile(bundleProject.getArtifact()); + if (outputFile.exists()) + outputFile.delete(); + bundle(bundleProject); + postProcessBundle(artifact, outputFile); + + } + } + + + @SuppressWarnings("unchecked") + private void postProcessBundle(Artifact artifact, File bundleFile) throws IOException { + + if (!bundleFile.exists()) + return; + + File processedFile = bundleFile; + boolean retainManifestEntries = false; + if (!artifact.getGroupId().equals("org.apache.tuscany.sca")) { + // For pre-bundled 3rd party bundles, retain all OSGi manifest entries except Require-Bundle + Manifest manifest = getManifest(artifact.getFile()); + if (manifest != null && manifest.getMainAttributes() != null && + manifest.getMainAttributes().getValue("Bundle-SymbolicName") != null) { + retainManifestEntries = true; + } + } + + Manifest manifest = getManifest(bundleFile); + Attributes attributes = manifest.getMainAttributes(); + + if (attributes == null) { + return; + } + + String artifactId = artifact.getGroupId() + ":" + artifact.getArtifactId(); + + String bundleSymName = (String)attributes.getValue("Bundle-SymbolicName"); + if (!bundleSymName.startsWith("org.apache.tuscany.sca")) { + bundleSymName = "org.apache.tuscany.sca.3rdparty." + bundleSymName; + attributes.putValue("Bundle-SymbolicName", bundleSymName); + + processedFile = new File(bundleFile.getParent(), "org.apache.tuscany.sca.3rdparty." + bundleFile.getName()); + } + + String imports = (String)attributes.getValue("Import-Package"); + String exports = (String)attributes.getValue("Export-Package"); + + // For EMF jars + if (attributes.getValue("Require-Bundle") != null) { + attributes.remove(new Attributes.Name("Require-Bundle")); + attributes.putValue("DynamicImport-Package", "*"); + attributes.remove(new Attributes.Name("Eclipse-LazyStart")); + } + + if (!retainManifestEntries && imports != null) { + StringBuilder newImportBuf = new StringBuilder(); + Map importMap = OSGiHeader.parseHeader(imports); + for (Object pkg : importMap.keySet()) { + + if (isPrivatePackage(artifactId, (String)pkg)) { + continue; + } + + Map importAttr = (Map)importMap.get(pkg); + String version = (String)importAttr.get("version"); + if (version != null && version.indexOf(',') == -1) { + if (((String)pkg).startsWith("org.osgi")) { + // Leave version as is - for OSGi packages, assume backward compatibility + } + else if (!version.matches(".*\\..*\\.")) { + Version curVersion = new Version(version); + Version nextVersion = new Version(curVersion.getMajor(), curVersion.getMinor()+1, 0); + version = '[' + version + ',' + nextVersion + ')'; + } + else + version = '[' + version + ',' + version + ']'; + importAttr.put("version", version); + } + updateManifestAttribute((String)pkg, importAttr, importDirectives, newImportBuf); + + } + attributes.putValue("Import-Package", newImportBuf.toString()); + } + + if (!retainManifestEntries && exports != null) { + StringBuilder newExportBuf = new StringBuilder(); + Map exportMap = OSGiHeader.parseHeader(exports); + + for (Object value : exportMap.keySet()) { + String pkg = (String)value; + if (!isPrivatePackage(artifactId, pkg)) { + Map exportAttr = (Map)exportMap.get(pkg); + updateManifestAttribute((String)pkg, exportAttr, exportDirectives, newExportBuf); + } + } + if (newExportBuf.length() > 0) + attributes.putValue("Export-Package", newExportBuf.toString()); + else + attributes.remove(new Attributes.Name("Export-Package")); + } + + String dynImport = dynamicImports.get(artifactId); + if (dynImport != null) + attributes.putValue("DynamicImport-Package", dynImport); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + JarOutputStream jarOut = new JarOutputStream(out, manifest); + copyJar(bundleFile, jarOut); + jarOut.close(); + out.close(); + bundleFile.delete(); + FileOutputStream fileOut = new FileOutputStream(processedFile); + fileOut.write(out.toByteArray()); + fileOut.close(); + + } + + + private void copyJar(File file, JarOutputStream jarOut) throws IOException { + + try { + JarInputStream jarIn = new JarInputStream(new FileInputStream(file)); + ZipEntry ze; + byte[] readBuf = new byte[1000]; + int bytesRead; + while ((ze = jarIn.getNextEntry()) != null) { + if (ze.getName().equals("META-INF/MANIFEST.MF")) + continue; + jarOut.putNextEntry(ze); + while ((bytesRead = jarIn.read(readBuf)) > 0) { + jarOut.write(readBuf, 0, bytesRead); + } + } + jarIn.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private Manifest getManifest(File jar) { + try { + JarInputStream jarIn = new JarInputStream(new FileInputStream(jar)); + Manifest manifest = jarIn.getManifest(); + if (manifest == null) { + ZipEntry ze; + while ((ze = jarIn.getNextEntry()) != null) { + if (ze.getName().equals("META-INF/MANIFEST.MF")) + break; + } + if (ze != null) { + byte[] bytes = new byte[(int)ze.getSize()]; + jarIn.read(bytes); + manifest = new Manifest(new ByteArrayInputStream(bytes)); + } + } + jarIn.close(); + return manifest; + } catch (IOException e) { + return null; + } + } + + private boolean isPrivatePackage(String artifactId, String pkg) { + String privatePkgs = privatePackages.get(artifactId); + if (privatePkgs != null) { + String[] pkgs = privatePkgs.split(","); + for (int i = 0; i < pkgs.length; i++) { + if (pkgs[i].trim().equals(pkg)) + return true; + } + } + return false; + } + + + private void updateManifestAttribute(String pkg, Map newMap, Set<String> directives, StringBuilder newAttrBuffer) { + if (newAttrBuffer.length() != 0) newAttrBuffer.append(','); + newAttrBuffer.append(pkg); + if (newMap.size() > 0) { + for (Object attrName : newMap.keySet()) { + newAttrBuffer.append(';'); + newAttrBuffer.append(attrName); + if (directives.contains(attrName)) + newAttrBuffer.append(":="); + else + newAttrBuffer.append('='); + newAttrBuffer.append('\"'); + newAttrBuffer.append(newMap.get(attrName)); + newAttrBuffer.append('\"'); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/LICENSE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/NOTICE b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/pom.xml new file mode 100644 index 0000000000..eb0c344d3f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-maven-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-maven-wsdl2java</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany SCA WSDL2Java Maven Plugin</name> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-wsdl2java</artifactId> + <version>1.5.2-SNAPSHOT</version> + </dependency> + </dependencies> +</project> diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDL2JavaGeneratorMojo.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDL2JavaGeneratorMojo.java new file mode 100644 index 0000000000..8021692521 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDL2JavaGeneratorMojo.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.tools.wsdl2java.plugin; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.List; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.tuscany.tools.wsdl2java.generate.WSDL2JavaGenerator; + +/** + * @version $Rev$ $Date$ + * @goal generate + * @phase generate-sources + * @description Generate SDO interface classes from an XML Schema + */ +public class WSDL2JavaGeneratorMojo extends AbstractMojo { + /** + * The directory containing WSDL files; defaults to ${basedir}/src/main/wsdl + * @parameter expression="${basedir}/src/main/wsdl" + */ + private String wsdlDir; + + /** + * Name of the WSDL file; if omitted all files in the directory are processed + * @parameter + */ + private File wsdlFile; + + /** + * The Java package to generate into. By default the value is derived from the schema URI. + * + * @parameter + */ + private String javaPackage; + + /** + * The directory to generate into; defaults to ${project.build.directory}/wsdl2java-source + * + * @parameter expression="${project.build.directory}/wsdl2java-source" + */ + private String targetDirectory; + + /** + * The directory to generate into; defaults to ${project.build.directory}/wsdl2java-source + * + * @parameter + */ + private WSDLFileOption[] wsdlFiles; + + /** + * @parameter expression="${project.compileSourceRoots}" + * @readonly + */ + private List compilerSourceRoots; + + public void execute() throws MojoExecutionException { + + if(null != wsdlFiles){ + for(int i=0; i< wsdlFiles.length ; ++i ){ + System.err.println("wsdlFiles" + wsdlFiles[i].getFileName()); + WSDLFileOption wf = wsdlFiles[i]; + + if(null == wf.getTargetDirectory()) + wf.setTargetDirectory(targetDirectory); + if(null == wf.getJavaPackage()){ + wf.setJavaPackage(javaPackage); + } + if(wf.getFileName() == null || wf.getFileName().length() ==0){ + throw new MojoExecutionException("no fileName specfied for wsdl."); + } + if(!wf.getFileName().canRead() || !wf.getFileName().isFile()){ + + throw new MojoExecutionException("file can not be read:"+wf.getFileName()); + } + + } + }else{ + + + + if (wsdlFile == null) { + + File[] files = new File(wsdlDir).listFiles(FILTER); + + wsdlFiles= new WSDLFileOption[files.length]; + for(int i= files.length -1; i> -1; --i){ + + + wsdlFiles[i] = new WSDLFileOption(); + wsdlFiles[i].setFileName(files[i]); + wsdlFiles[i].setJavaPackage(javaPackage); + wsdlFiles[i].setPorts(null); + wsdlFiles[i].setTargetDirectory(targetDirectory); + + + } + + } else { + wsdlFiles= new WSDLFileOption[]{new WSDLFileOption()}; + wsdlFiles[0].setFileName(wsdlFile); + wsdlFiles[0].setJavaPackage(javaPackage); + wsdlFiles[0].setPorts(null); + wsdlFiles[0].setTargetDirectory(targetDirectory); + } + } + + int genOptions = 0; + + for (int i = 0; i < wsdlFiles.length; i++) { + File file = wsdlFiles[i].getFileName(); + File marker = new File(targetDirectory, ".gen#" + file.getName()+".wsdl2java"); + if (file.lastModified() > marker.lastModified()) { + getLog().info("Generating Java service interfaces from " + file); + WSDL2JavaGenerator.generateFromWSDL(file.toString(), wsdlFiles[i].getPorts(), wsdlFiles[i].getTargetDirectory(), wsdlFiles[i].getJavaPackage(), null, genOptions); + } + try { + marker.createNewFile(); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + marker.setLastModified(System.currentTimeMillis()); + } + + compilerSourceRoots.add(targetDirectory); + } + + private static final FileFilter FILTER = new FileFilter() { + public boolean accept(File pathname) { + return (pathname.isFile() || !pathname.isHidden()); + } + }; +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDLFileOption.java b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDLFileOption.java new file mode 100644 index 0000000000..cc10c351b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDLFileOption.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.tools.wsdl2java.plugin; + +import java.io.File; + +public class WSDLFileOption { + /** + * Name of the WSDL file; if omitted all files in the directory are processed + * + */ + private File fileName; + + /** + * The Java package to generate into. By default the value is derived from the schema URI. + * + * + */ + private String javaPackage; + + /** + * The directory to generate into; defaults to ${project.build.directory}/wsdl2java-source + * + * + */ + private String targetDirectory; + + /** + * @parameter expression="${project.compileSourceRoots}" + * @readonly + */ + + private String ports[]; + + /** + * @parameter expression="${project.compileSourceRoots}" + * @readonly + */ + + + public WSDLFileOption(){} + + public String getJavaPackage() { + return javaPackage; + } + + public void setJavaPackage(String javaPackage) { + this.javaPackage = javaPackage; + } + + + public String[] getPorts() { + return ports; + } + + public void setPorts(String[] ports) { + this.ports = ports; + } + + public String getTargetDirectory() { + return targetDirectory; + } + + public void setTargetDirectory(String targetDirectory) { + this.targetDirectory = targetDirectory; + } + + public File getFileName() { + return fileName; + } + + public void setFileName(File fileName) { + this.fileName = fileName; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/pom.xml b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/pom.xml new file mode 100644 index 0000000000..18ab2bd96a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/tools/maven/pom.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-tools</artifactId> + <version>1.5.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <packaging>pom</packaging> + <artifactId>tuscany-sca-maven-tools</artifactId> + <name>Apache Tuscany SCA Maven Tools</name> + + <profiles> + <profile> + <id>default</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <modules> + <module>maven-ant-generator</module> + <module>maven-dependency-lister</module> + <module>maven-incremental-build</module> + <module>maven-java2wsdl</module> + <module>maven-wsdl2java</module> + <module>maven-tuscany-bundle-plugin</module> + </modules> + </profile> + </profiles> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.2</version> + <scope>test</scope> + </dependency> + </dependencies> + +</project> |