Author: rfeng
Date: Wed Nov 12 17:40:16 2008
New Revision: 713611
URL: http://svn.apache.org/viewvc?rev=713611&view=rev
Log:
Resolve bundles after the compilation is done.
Modified:
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java
Modified:
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java?rev=713611&r1=713610&r2=713611&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java
(original)
+++
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/JavaCompiler.java
Wed Nov 12 17:40:16 2008
@@ -33,6 +33,7 @@
import static org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WARNING;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -44,6 +45,7 @@
import java.util.Set;
import org.apache.tuscany.sca.tools.maven.compiler.osgi.BundleResolver;
+import org.apache.tuscany.sca.tools.maven.compiler.osgi.BundleUtil;
import org.codehaus.plexus.compiler.AbstractCompiler;
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerError;
@@ -73,46 +75,15 @@
getLogger().info("Invoking Tuscany Eclipse JDT compiler");
- //
getLogger().info(configuration.getCustomCompilerArguments().toString());
- boolean osgi =
"true".equals(configuration.getCustomCompilerArguments().get("-osgi"));
- if (osgi) {
- getLogger().info("Enforcing OSGi bundle resolution");
- }
List<URL> urls = new ArrayList<URL>();
try {
- // urls.add(new
File(configuration.getOutputLocation()).toURI().toURL());
for (String entry :
(List<String>)configuration.getClasspathEntries()) {
- if (osgi) {
- try {
- File cp = new File(entry);
- if (cp.exists()) {
- stateController.addBundle(cp);
- }
- } catch (BundleException e) {
- getLogger().error(e.getMessage(), e);
- }
- }
urls.add(new File(entry).toURI().toURL());
}
} catch (MalformedURLException e) {
throw new CompilerException(e.getMessage(), e);
}
- if (osgi) {
- stateController.resolveState();
- for (BundleDescription b : stateController.getBundles()) {
- if (b != null) {
- try {
- stateController.assertResolved(b);
- } catch (BundleException e) {
-
getLogger().error(stateController.getAllErrors().toString());
- // FIXME: For now, only a warning is reported
- // throw new CompilerException(e.getMessage(), e);
- }
- }
- }
- }
-
ClassLoader classLoader = new URLClassLoader(urls.toArray(new
URL[urls.size()]));
// Determine compiler configuration
@@ -188,6 +159,43 @@
getLogger().info("Compiling " + compilationUnits.size() + " to " +
configuration.getOutputLocation());
compiler.compile((ICompilationUnit[])compilationUnits.toArray(new
ICompilationUnit[compilationUnits.size()]));
+ //
getLogger().info(configuration.getCustomCompilerArguments().toString());
+ boolean osgi =
"true".equals(configuration.getCustomCompilerArguments().get("-osgi"));
+ File proj = new File(configuration.getOutputLocation());
+ String symbol = null;
+ try {
+ symbol = BundleUtil.getBundleSymbolicName(proj);
+ } catch (IOException e1) {
+ symbol = null;
+ }
+
+ if (osgi && symbol != null) {
+ getLogger().info("Resolving OSGi bundles");
+ for (String entry :
(List<String>)configuration.getClasspathEntries()) {
+ try {
+ File cp = new File(entry);
+ if (cp.exists()) {
+ stateController.addBundle(cp);
+ }
+ } catch (BundleException e) {
+ getLogger().error(e.getMessage(), e);
+ }
+ }
+
+ stateController.resolveState();
+ BundleDescription b = stateController.getBundleDescription(proj);
+ if (b != null) {
+ try {
+ stateController.assertResolved(b);
+ getLogger().info("OSGi bundle is resolved: " +
b.getSymbolicName());
+ } catch (BundleException e) {
+
getLogger().error(stateController.getAllErrors().toString());
+ // FIXME: For now, only a warning is reported
+ // throw new CompilerException(e.getMessage(), e);
+ }
+ }
+ }
+
return compilerErrors;
}
Modified:
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java?rev=713611&r1=713610&r2=713611&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java
(original)
+++
tuscany/branches/sca-equinox/tools/maven/maven-eclipse-compiler/src/main/java/org/apache/tuscany/sca/tools/maven/compiler/osgi/BundleUtil.java
Wed Nov 12 17:40:16 2008
@@ -59,7 +59,7 @@
*
* @version $Rev$ $Date$
*/
-final class BundleUtil {
+public final class BundleUtil {
/**
* Returns the name of a bundle, or null if the given file is not a bundle.
@@ -68,13 +68,16 @@
* @return
* @throws IOException
*/
- static String getBundleSymbolicName(File file) throws IOException {
+ public static String getBundleSymbolicName(File file) throws IOException {
if (!file.exists()) {
return null;
}
String bundleName = null;
if (file.isDirectory()) {
File mf = new File(file, JarFile.MANIFEST_NAME);
+ if (!mf.isFile()) {
+ mf = new File(file, "../../" + JarFile.MANIFEST_NAME);
+ }
if (mf.isFile()) {
Manifest manifest = new Manifest(new FileInputStream(mf));
bundleName =
manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);