Author: hibou
Date: Wed Aug 28 21:17:46 2013
New Revision: 1518390
URL: http://svn.apache.org/r1518390
Log:
Little bit of refactoring
Added:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.apache.ivyde.eclipse.prefs
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java
(with props)
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/
(props changed)
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl.ui/META-INF/MANIFEST.MF
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.classpath
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.launch/AntDSL.launch
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.project
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.eclipse.jdt.core.prefs
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/META-INF/MANIFEST.MF
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSLArgProcessor.java
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
Propchange: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Aug 28 21:17:46 2013
@@ -2,4 +2,5 @@ bin
plugin.xml_gen
.antlr-generator-3.2.0.jar
lib
+target
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl.ui/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl.ui/META-INF/MANIFEST.MF?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl.ui/META-INF/MANIFEST.MF
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl.ui/META-INF/MANIFEST.MF
Wed Aug 28 21:17:46 2013
@@ -21,5 +21,6 @@ Import-Package: org.apache.log4j,
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.apache.ant.antdsl.xtext.ui.contentassist,
org.apache.ant.antdsl.xtext.ui.contentassist.antlr,
- org.apache.ant.antdsl.xtext.ui.internal
+ org.apache.ant.antdsl.xtext.ui.internal,
+ org.apache.ant.antdsl.xtext.ui.quickfix
Bundle-Activator: org.apache.ant.antdsl.xtext.ui.internal.AntDSLActivator
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.classpath
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.classpath?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
Binary files - no diff available.
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.launch/AntDSL.launch
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.launch/AntDSL.launch?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
Binary files - no diff available.
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.project
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.project?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.project
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.project
Wed Aug 28 21:17:46 2013
@@ -1,22 +1,4 @@
<?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.
--->
<projectDescription>
<name>org.apache.ant.antdsl</name>
<comment></comment>
@@ -48,5 +30,6 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+ <nature>org.apache.ivyde.eclipse.ivynature</nature>
</natures>
</projectDescription>
Added:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.apache.ivyde.eclipse.prefs
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.apache.ivyde.eclipse.prefs?rev=1518390&view=auto
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.apache.ivyde.eclipse.prefs
(added)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.apache.ivyde.eclipse.prefs
Wed Aug 28 21:17:46 2013
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.apache.ivyde.eclipse.standaloneretrieve=<?xml version\="1.0"
encoding\="UTF-8" standalone\="no"?><setuplist><setup name\="dependencies"
resolveInWorkspace\="false"><ivysettings ivyUserDir\="" loadondemand\="false"
path\="${workspace_loc\:antdsl-build/ivysettings.xml}"/><ivyxml
path\="ivy.xml"/><retrieve confs\="*"
pattern\="lib/[type]s/[artifact]-[revision].[ext]" sync\="true"
types\="*"/></setup></setuplist>
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.eclipse.jdt.core.prefs
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.eclipse.jdt.core.prefs?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.eclipse.jdt.core.prefs
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.settings/org.eclipse.jdt.core.prefs
Wed Aug 28 21:17:46 2013
@@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/META-INF/MANIFEST.MF?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/META-INF/MANIFEST.MF
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/META-INF/MANIFEST.MF
Wed Aug 28 21:17:46 2013
@@ -2,11 +2,11 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.apache.ant.antdsl
Bundle-Vendor: Apache Software Fundation
-Bundle-Version: 1.0.0
+Bundle-Version: 1.0.0.qualifier
Bundle-SymbolicName: org.apache.ant.antdsl; singleton:=true
Bundle-ActivationPolicy: lazy
-Require-Bundle: org.eclipse.xtext;bundle-version="2.3.1";visibility:=reexport,
-
org.eclipse.xtext.xbase;bundle-version="2.3.1";resolution:=optional;visibility:=reexport,
+Require-Bundle: org.eclipse.xtext;visibility:=reexport,
+ org.eclipse.xtext.xbase;resolution:=optional;visibility:=reexport,
org.apache.log4j;bundle-version="1.2.15";visibility:=reexport,
org.apache.commons.logging;bundle-version="1.0.4";resolution:=optional;visibility:=reexport,
org.eclipse.xtext.generator;resolution:=optional,
@@ -18,7 +18,9 @@ Require-Bundle: org.eclipse.xtext;bundle
org.eclipse.emf.common,
org.antlr.runtime,
org.eclipse.xtext.common.types,
- org.apache.ant;bundle-version="1.8.0"
+ org.apache.ant;bundle-version="1.8.0",
+ org.apache.ivy;bundle-version="2.4.0",
+ org.eclipse.osgi;bundle-version="3.8.2"
Import-Package: org.apache.log4j,
org.apache.commons.logging,
org.eclipse.xtext.xbase.lib,
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
Wed Aug 28 21:17:46 2013
@@ -19,15 +19,10 @@ package org.apache.ant.antdsl;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.nio.charset.Charset;
-import java.text.ParseException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
@@ -43,16 +38,6 @@ import org.apache.ant.antdsl.expr.AntExp
import org.apache.ant.antdsl.expr.AntExpressionCondition;
import org.apache.ant.antdsl.expr.ConditionAntExpression;
import org.apache.ant.antdsl.expr.func.FunctionRegistry;
-import org.apache.ivy.Ivy;
-import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
-import org.apache.ivy.core.report.ArtifactDownloadReport;
-import org.apache.ivy.core.report.ResolveReport;
-import org.apache.ivy.core.resolve.ResolveOptions;
-import org.apache.ivy.osgi.core.BundleInfo;
-import org.apache.ivy.osgi.core.ManifestParser;
-import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
-import org.apache.ivy.util.filter.Filter;
-import org.apache.ivy.util.filter.FilterHelper;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExtensionPoint;
import org.apache.tools.ant.MagicNames;
@@ -78,7 +63,7 @@ import org.osgi.framework.BundleExceptio
public abstract class AbstractAntDslProjectHelper extends ProjectHelper {
- private static final String REFID_CONTEXT = "antdsl.parsingcontext";
+ private static final String REFID_CONTEXT = "antdsl.parsingcontext";
public static final String REFID_FUNCTION_REGISTRY =
"antdsl.function.registry";
@@ -88,9 +73,7 @@ public abstract class AbstractAntDslProj
public static final String REFID_ANT_PATH = "antdsl.path";
- public static final String REFID_UPDATE_BUILD = "antdsl.update-build";
-
- private static final Charset UTF8 = Charset.forName("UTF-8");
+ private AntPathManager antPathManager = new AntPathManager();
public String getDefaultBuildFile() {
return "build.ant";
@@ -350,11 +333,7 @@ public abstract class AbstractAntDslProj
antPath = new Path(project);
}
- if (Boolean.TRUE.equals(project.getReference(REFID_UPDATE_BUILD))) {
- updateBuild(project, antPath);
- } else {
- readAntPath(project, antPath);
- }
+ antPathManager.readAntPath(project, antPath);
if (!antpathElements.isEmpty()) {
UnknownElement element = new UnknownElement("path");
@@ -399,178 +378,6 @@ public abstract class AbstractAntDslProj
}
}
- private void updateBuild(Project project, Path antPath) {
- File ivyFile = new File(project.getBaseDir(), "ant/ivy.xml");
- if (!ivyFile.exists()) {
- return;
- }
-
- Ivy ivy = configureBuildIvy(project);
-
- ResolveReport report = resolveBuild(project, ivyFile, ivy);
- writeIvyFixed(project, ivy, report);
- Path ivyPath = getIvyBuildPath(project, report);
- writePath(project, ivyPath);
- antPath.add(ivyPath);
- }
-
- private void writeIvyFixed(Project project, Ivy ivy, ResolveReport report)
{
- File ivyFixFile = new File(project.getBaseDir(), "ant/ivy-fixed.xml");
- ModuleDescriptor md =
report.toFixedModuleDescriptor(ivy.getSettings());
- try {
- XmlModuleDescriptorWriter.write(md, ivyFixFile);
- } catch (IOException e) {
- throw new BuildException("Failed to write into the file " +
ivyFixFile + " (" + e.getMessage() + ")", e);
- }
- }
-
- private ResolveReport resolveBuild(Project project, File ivyFile, Ivy ivy)
{
- ResolveReport report;
- try {
- ResolveOptions options = new ResolveOptions();
- options.setUncompress(true);
- report = ivy.resolve(ivyFile, options);
- } catch (ParseException e) {
- throw new BuildException("The ivy file " + ivyFile + " could not
be parsed", e);
- } catch (IOException e) {
- throw new BuildException("The ivy file " + ivyFile + " could not
be read", e);
- }
- if (report.hasError()) {
- @SuppressWarnings("unchecked")
- List<String> errors = (List<String>)
report.getAllProblemMessages();
- for (String error : errors) {
- project.log(error, Project.MSG_ERR);
- }
- throw new BuildException("Resolve of the build path failed");
- }
- return report;
- }
-
- private Ivy configureBuildIvy(Project project) {
- Ivy ivy = Ivy.newInstance();
-
- File ivysettingsFile = new File(project.getBaseDir(),
"ant/ivysettings.xml");
- if (ivysettingsFile.exists()) {
- try {
- ivy.configure(ivysettingsFile);
- } catch (ParseException e) {
- throw new BuildException("The ivysettings file " +
ivysettingsFile + " could not be parsed", e);
- } catch (IOException e) {
- throw new BuildException("The ivysettings file " +
ivysettingsFile + " could not be read", e);
- }
- } else {
- try {
- ivy.configureDefault();
- } catch (ParseException e) {
- throw new BuildException("The default ivysettings file could
not be parsed", e);
- } catch (IOException e) {
- throw new BuildException("The default ivysettings file could
not be read", e);
- }
- }
- return ivy;
- }
-
- private void readAntPath(Project project, Path antPath) {
- File antPathFile = new File(project.getBaseDir(), "ant/ant.path");
- if (!antPathFile.exists()) {
- File ivyFixFile = new File(project.getBaseDir(),
"ant/ivy-fixed.xml");
- if (!ivyFixFile.exists()) {
- updateBuild(project, antPath);
- return;
- }
- Ivy ivy = configureBuildIvy(project);
- ResolveReport report = resolveBuild(project, ivyFixFile, ivy);
- Path ivyPath = getIvyBuildPath(project, report);
- writePath(project, ivyPath);
- antPath.add(ivyPath);
- return;
- }
-
- String path;
- try {
- path = FileUtils.readFully(new FileReader(antPathFile));
- } catch (FileNotFoundException e) {
- throw new BuildException("The cached ant path " + antPathFile + "
has been deleted juste before reading it", e);
- } catch (IOException e) {
- throw new BuildException("The cached ant path " + antPathFile + "
cannot be read", e);
- }
- antPath.createPathElement().setPath(path);
- }
-
- private Path getIvyBuildPath(Project project, ResolveReport report) {
- // TODO make it configurable
- boolean uncompress = true;
- boolean osgi = true;
- Filter artifactfilter = FilterHelper.getArtifactTypeFilter(new
String[] {"bundle", "jar"});
-
- Path ivyPath = new Path(project);
- for (ArtifactDownloadReport adr : report.getAllArtifactsReports()) {
- if (artifactfilter.accept(adr.getArtifact())) {
- File f = adr.getLocalFile();
- if (uncompress && adr.getUncompressedLocalDir() != null) {
- f = adr.getUncompressedLocalDir();
- }
- addToPath(ivyPath, f, osgi);
- }
- }
- return ivyPath;
- }
-
- private void writePath(Project project, Path ivyPath) {
- File antPathFile = new File(project.getBaseDir(), "ant/ant.path");
- FileOutputStream out;
- try {
- out = new FileOutputStream(antPathFile);
- } catch (FileNotFoundException e) {
- throw new BuildException("The cached ant path " + antPathFile +
"could not be written", e);
- }
- try {
- out.write(ivyPath.toString().getBytes(UTF8.name()));
- } catch (IOException e) {
- throw new BuildException("The cached ant path " + antPathFile +
"could not be written", e);
- } finally {
- try {
- out.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
-
- private void addToPath(Path path, File f, boolean osgi) {
- if (!osgi || !f.isDirectory()) {
- path.createPathElement().setLocation(f);
- return;
- }
- File manifest = new File(f, "META-INF/MANIFEST.MF");
- if (!manifest.exists()) {
- path.createPathElement().setLocation(f);
- return;
- }
- BundleInfo bundleInfo;
- try {
- bundleInfo = ManifestParser.parseManifest(manifest);
- } catch (IOException e) {
- throw new BuildException("The manifest " + manifest + " could not
be read", e);
- } catch (ParseException e) {
- throw new BuildException("The manifest " + manifest + " could not
be parsed", e);
- }
- @SuppressWarnings("unchecked")
- List<String> cp = bundleInfo.getClasspath();
- if (cp == null) {
- path.createPathElement().setLocation(f);
- return;
- }
- for (int i = 0; i < cp.size(); i++) {
- String p = (String) cp.get(i);
- if (p.equals(".")) {
- path.createPathElement().setLocation(f);
- } else {
- path.createPathElement().setLocation(new File(f, p));
- }
- }
- }
-
protected void importAntlib(Project project, AntDslContext context, String
name, String resource) {
// TODO maybe we can do some caching here, each time a build module
import the exact same antlib, it is reloaded
@@ -658,7 +465,6 @@ public abstract class AbstractAntDslProj
context.addTarget(target);
target.setProject(project);
- target.setName(name);
target.setDescription(description);
String fqnPrefix;
@@ -668,6 +474,7 @@ public abstract class AbstractAntDslProj
fqnPrefix = "";
}
String fqn = fqnPrefix + name;
+ target.setName(fqn);
// Check if this target is in the current build file
if (context.getCurrentTargets().get(fqn) != null) {
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSL.g
Wed Aug 28 21:17:46 2013
@@ -64,7 +64,7 @@ project:
('basedir' ':' basedir=stringLiteral)?
)
{ projectHelper.setupProject(project, context, name, basedir, def); }
- ( 'namespaces' '{' ( ns=namespace { context.addNamespace(ns.first,
ns.second); } )* '}')?
+ ( 'namespaces' '{' ( ns=namespace { context.addFQNPrefix(ns.first,
ns.second); } )* '}')?
tl=taskList?
{ for (Task t : tl) { context.getImplicitTarget().addTask(t); } }
( target
@@ -108,9 +108,14 @@ taskList returns [List<Task> tl = new Ar
'{' (t=task { tl.add(t); } )* '}'
;
-targetList returns [List<String> tl = new ArrayList<String>()]:
- n=identifier { tl.add(n); }
- (',' n=identifier { tl.add(n); } )*
+targetList returns [List<Pair<String, String>> tl = new ArrayList<Pair<String,
String>>()]:
+ ensn=ensName { tl.add(ensn); }
+ (',' ensn=ensName { tl.add(ensn); } )*
+;
+
+ensName returns [Pair<String, String> pair = null]:
+ (ns=identifier ':')? name=identifier
+ { pair = new Pair<String, String>(ns, name); }
;
task returns [Task t = null]:
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSLArgProcessor.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSLArgProcessor.java?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSLArgProcessor.java
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntDSLArgProcessor.java
Wed Aug 28 21:17:46 2013
@@ -1,3 +1,20 @@
+/*
+ * 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.ant.antdsl;
import java.io.PrintStream;
@@ -20,7 +37,7 @@ public class AntDSLArgProcessor implemen
}
public void prepareConfigure(Project project, List<String> extraArgs) {
- project.addReference(AbstractAntDslProjectHelper.REFID_UPDATE_BUILD,
true);
+ project.addReference(AntPathManager.REFID_UPDATE_BUILD, true);
}
public boolean handleArg(Project project, List<String> arg) {
Added:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java?rev=1518390&view=auto
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java
(added)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java
Wed Aug 28 21:17:46 2013
@@ -0,0 +1,236 @@
+/*
+ * 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.ant.antdsl;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.text.ParseException;
+import java.util.List;
+
+import org.apache.ivy.Ivy;
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.report.ArtifactDownloadReport;
+import org.apache.ivy.core.report.ResolveReport;
+import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.ivy.osgi.core.BundleInfo;
+import org.apache.ivy.osgi.core.ManifestParser;
+import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
+import org.apache.ivy.util.filter.Filter;
+import org.apache.ivy.util.filter.FilterHelper;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.util.FileUtils;
+
+class AntPathManager {
+
+ private static final String IVY_XML_LOCATION = "ant/ivy.xml";
+
+ private static final String IVY_FIXED_XML_LOCATION =
"ant/ivy-fixed.xml";
+
+ private static final String ANT_PATH_LOCATION = "ant/ant.path";
+
+ static final String OSGI_STORAGE_LOCATION = "ant/osgi-storage";
+
+ public static final String REFID_UPDATE_BUILD = "antdsl.update-build";
+
+ private static final Charset UTF8 = Charset.forName("UTF-8");
+
+ void readAntPath(Project project, Path antPath) {
+ File ivyFile = new File(project.getBaseDir(), IVY_XML_LOCATION);
+ if (!ivyFile.exists()) {
+ // no ivy file, just an empty path then
+ return;
+ }
+ File ivyFixFile = new File(project.getBaseDir(),
IVY_FIXED_XML_LOCATION);
+ Boolean updateBuild = (Boolean)
project.getReference(REFID_UPDATE_BUILD);
+ if (Boolean.TRUE.equals(updateBuild) || !ivyFixFile.exists() ||
ivyFixFile.lastModified() < ivyFile.lastModified()) {
+ updateBuild(project, antPath);
+ return;
+ }
+ File antPathFile = new File(project.getBaseDir(), ANT_PATH_LOCATION);
+ if (!antPathFile.exists() || antPathFile.lastModified() <
ivyFixFile.lastModified()) {
+ Ivy ivy = configureBuildIvy(project);
+ ResolveReport report = resolveBuild(project, ivyFixFile, ivy);
+ Path ivyPath = getIvyBuildPath(project, report);
+ writePath(project, ivyPath);
+ antPath.add(ivyPath);
+ return;
+ }
+
+ String path;
+ try {
+ path = FileUtils.readFully(new FileReader(antPathFile));
+ } catch (FileNotFoundException e) {
+ throw new BuildException("The cached ant path " + antPathFile + "
has been deleted juste before reading it", e);
+ } catch (IOException e) {
+ throw new BuildException("The cached ant path " + antPathFile + "
cannot be read", e);
+ }
+ antPath.createPathElement().setPath(path);
+ }
+
+ private Path getIvyBuildPath(Project project, ResolveReport report) {
+ // TODO make it configurable
+ boolean uncompress = true;
+ boolean osgi = true;
+ Filter artifactfilter = FilterHelper.getArtifactTypeFilter(new
String[] {"bundle", "jar"});
+
+ Path ivyPath = new Path(project);
+ for (ArtifactDownloadReport adr : report.getAllArtifactsReports()) {
+ if (artifactfilter.accept(adr.getArtifact())) {
+ File f = adr.getLocalFile();
+ if (uncompress && adr.getUncompressedLocalDir() != null) {
+ f = adr.getUncompressedLocalDir();
+ }
+ addToPath(ivyPath, f, osgi);
+ }
+ }
+ return ivyPath;
+ }
+
+ private void writePath(Project project, Path ivyPath) {
+ File antPathFile = new File(project.getBaseDir(), ANT_PATH_LOCATION);
+ FileOutputStream out;
+ try {
+ out = new FileOutputStream(antPathFile);
+ } catch (FileNotFoundException e) {
+ throw new BuildException("The cached ant path " + antPathFile +
"could not be written", e);
+ }
+ try {
+ out.write(ivyPath.toString().getBytes(UTF8.name()));
+ } catch (IOException e) {
+ throw new BuildException("The cached ant path " + antPathFile +
"could not be written", e);
+ } finally {
+ try {
+ out.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ private void addToPath(Path path, File f, boolean osgi) {
+ if (!osgi || !f.isDirectory()) {
+ path.createPathElement().setLocation(f);
+ return;
+ }
+ File manifest = new File(f, "META-INF/MANIFEST.MF");
+ if (!manifest.exists()) {
+ path.createPathElement().setLocation(f);
+ return;
+ }
+ BundleInfo bundleInfo;
+ try {
+ bundleInfo = ManifestParser.parseManifest(manifest);
+ } catch (IOException e) {
+ throw new BuildException("The manifest " + manifest + " could not
be read", e);
+ } catch (ParseException e) {
+ throw new BuildException("The manifest " + manifest + " could not
be parsed", e);
+ }
+ @SuppressWarnings("unchecked")
+ List<String> cp = bundleInfo.getClasspath();
+ if (cp == null) {
+ path.createPathElement().setLocation(f);
+ return;
+ }
+ for (int i = 0; i < cp.size(); i++) {
+ String p = (String) cp.get(i);
+ if (p.equals(".")) {
+ path.createPathElement().setLocation(f);
+ } else {
+ path.createPathElement().setLocation(new File(f, p));
+ }
+ }
+ }
+
+ private void updateBuild(Project project, Path antPath) {
+ File ivyFile = new File(project.getBaseDir(), IVY_XML_LOCATION);
+ if (!ivyFile.exists()) {
+ return;
+ }
+
+ Ivy ivy = configureBuildIvy(project);
+
+ ResolveReport report = resolveBuild(project, ivyFile, ivy);
+ writeIvyFixed(project, ivy, report);
+ Path ivyPath = getIvyBuildPath(project, report);
+ writePath(project, ivyPath);
+ antPath.add(ivyPath);
+ }
+
+ private void writeIvyFixed(Project project, Ivy ivy, ResolveReport report)
{
+ File ivyFixFile = new File(project.getBaseDir(),
IVY_FIXED_XML_LOCATION);
+ ModuleDescriptor md =
report.toFixedModuleDescriptor(ivy.getSettings(), null);
+ try {
+ XmlModuleDescriptorWriter.write(md, ivyFixFile);
+ } catch (IOException e) {
+ throw new BuildException("Failed to write into the file " +
ivyFixFile + " (" + e.getMessage() + ")", e);
+ }
+ }
+
+ private ResolveReport resolveBuild(Project project, File ivyFile, Ivy ivy)
{
+ ResolveReport report;
+ try {
+ ResolveOptions options = new ResolveOptions();
+ options.setUncompress(true);
+ report = ivy.resolve(ivyFile, options);
+ } catch (ParseException e) {
+ throw new BuildException("The ivy file " + ivyFile + " could not
be parsed", e);
+ } catch (IOException e) {
+ throw new BuildException("The ivy file " + ivyFile + " could not
be read", e);
+ }
+ if (report.hasError()) {
+ @SuppressWarnings("unchecked")
+ List<String> errors = (List<String>)
report.getAllProblemMessages();
+ for (String error : errors) {
+ project.log(error, Project.MSG_ERR);
+ }
+ throw new BuildException("Resolve of the build path failed");
+ }
+ return report;
+ }
+
+ private Ivy configureBuildIvy(Project project) {
+ Ivy ivy = Ivy.newInstance();
+
+ File ivysettingsFile = new File(project.getBaseDir(),
"ant/ivysettings.xml");
+ if (ivysettingsFile.exists()) {
+ try {
+ ivy.configure(ivysettingsFile);
+ } catch (ParseException e) {
+ throw new BuildException("The ivysettings file " +
ivysettingsFile + " could not be parsed", e);
+ } catch (IOException e) {
+ throw new BuildException("The ivysettings file " +
ivysettingsFile + " could not be read", e);
+ }
+ } else {
+ try {
+ ivy.configureDefault();
+ } catch (ParseException e) {
+ throw new BuildException("The default ivysettings file could
not be parsed", e);
+ } catch (IOException e) {
+ throw new BuildException("The default ivysettings file could
not be read", e);
+ }
+ }
+ return ivy;
+ }
+
+}
Propchange:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AntPathManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
URL:
http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java?rev=1518390&r1=1518389&r2=1518390&view=diff
==============================================================================
---
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
(original)
+++
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
Wed Aug 28 21:17:46 2013
@@ -1,3 +1,20 @@
+/*
+ * 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.ant.antdsl;
import java.io.BufferedReader;
@@ -20,9 +37,9 @@ import org.osgi.framework.launch.Framewo
import org.osgi.framework.launch.FrameworkFactory;
import org.osgi.framework.wiring.BundleWiring;
-public class OSGiFrameworkManager {
+class OSGiFrameworkManager {
- //@formatter:off
+ //@formatter:off
private static final String ANT_PACKAGES =
"org.apache.tools.ant,"
+ "org.apache.tools.ant.types,"
@@ -37,10 +54,10 @@ public class OSGiFrameworkManager {
private GodClassLoader godClassLoader = new GodClassLoader();
- public OSGiFrameworkManager(File basedir) throws BundleException {
+ OSGiFrameworkManager(File basedir) throws BundleException {
Map<String, String> configMap = new HashMap<String, String>();
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, ANT_PACKAGES);
- configMap.put(Constants.FRAMEWORK_STORAGE, new File(basedir,
"ant/felix-cache").getAbsolutePath());
+ configMap.put(Constants.FRAMEWORK_STORAGE, new File(basedir,
AntPathManager.OSGI_STORAGE_LOCATION).getAbsolutePath());
configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN, "true");
framework = getFrameworkFactory().newFramework(configMap);
framework.init();
@@ -59,6 +76,7 @@ public class OSGiFrameworkManager {
URL url = null;
ArrayList<URL> urlList = Collections.list(urls);
for (URL candidate : urlList) {
+ // we prefer using felix (equinox might be somewhere in the
classpath too within Eclipse)
if (candidate.toExternalForm().contains("felix")) {
url = candidate;
}
@@ -90,7 +108,7 @@ public class OSGiFrameworkManager {
throw new BuildException("No OSGi framework factory found");
}
- public void install(String bundleURI) throws BundleException {
+ void install(String bundleURI) throws BundleException {
if (bundleURI.startsWith("file:")) {
bundleURI = "reference:" + bundleURI;
}
@@ -104,7 +122,7 @@ public class OSGiFrameworkManager {
return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
}
- public void start() throws BundleException {
+ void start() throws BundleException {
framework.start();
Runtime.getRuntime().addShutdownHook(new Thread("OSGi Framwork
Shutdown Hook") {
public void run() {
@@ -114,7 +132,8 @@ public class OSGiFrameworkManager {
framework.waitForStop(0);
}
} catch (Exception ex) {
- System.err.println("Error stopping framework: " + ex);
+ System.err.println("Error stopping framework: " +
ex.getMessage());
+ ex.printStackTrace();
}
}
});
@@ -123,11 +142,11 @@ public class OSGiFrameworkManager {
}
}
- public GodClassLoader getGodClassLoader() {
+ GodClassLoader getGodClassLoader() {
return godClassLoader;
}
- public List<Bundle> getBundles() {
+ List<Bundle> getBundles() {
return bundles;
}
@@ -136,9 +155,9 @@ public class OSGiFrameworkManager {
*
* @return
*/
- public ClassLoader getClassLoader(String resource, URL url) {
+ ClassLoader getClassLoader(String resource, URL url) {
for (Bundle bundle : bundles) {
- BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ BundleWiring wiring = (BundleWiring)
bundle.adapt(BundleWiring.class);
int i = resource.lastIndexOf('/');
String path = resource.substring(0, i);
String name = resource.substring(i + 1);
@@ -175,7 +194,7 @@ public class OSGiFrameworkManager {
@Override
public URL getResource(String name) {
for (Bundle bundle : bundles) {
- BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ BundleWiring wiring = (BundleWiring)
bundle.adapt(BundleWiring.class);
ClassLoader cl = wiring.getClassLoader();
URL url = cl.getResource(name);
if (url != null) {
@@ -189,7 +208,7 @@ public class OSGiFrameworkManager {
public Enumeration<URL> getResources(String name) throws IOException {
List<URL> urls = new ArrayList<URL>();
for (Bundle bundle : bundles) {
- BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ BundleWiring wiring = (BundleWiring)
bundle.adapt(BundleWiring.class);
ClassLoader cl = wiring.getClassLoader();
Enumeration<URL> resources = cl.getResources(name);
if (resources != null) {
@@ -202,7 +221,7 @@ public class OSGiFrameworkManager {
@Override
public Class< ? > loadClass(String name) throws ClassNotFoundException
{
for (Bundle bundle : bundles) {
- BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ BundleWiring wiring = (BundleWiring)
bundle.adapt(BundleWiring.class);
ClassLoader cl = wiring.getClassLoader();
try {
return cl.loadClass(name);