Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 63301 invoked from network); 29 Sep 2009 12:58:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Sep 2009 12:58:28 -0000 Received: (qmail 94407 invoked by uid 500); 29 Sep 2009 12:58:28 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 94366 invoked by uid 500); 29 Sep 2009 12:58:28 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 94357 invoked by uid 99); 29 Sep 2009 12:58:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Sep 2009 12:58:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Sep 2009 12:58:26 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F380423888BB; Tue, 29 Sep 2009 12:58:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r819912 - in /felix/trunk/sigil: common/core/src/org/apache/felix/sigil/config/ ivy/resolver/src/org/apache/felix/sigil/ant/ Date: Tue, 29 Sep 2009 12:58:05 -0000 To: commits@felix.apache.org From: dbaum@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090929125805.F380423888BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dbaum Date: Tue Sep 29 12:58:05 2009 New Revision: 819912 URL: http://svn.apache.org/viewvc?rev=819912&view=rev Log: enhance variable substitution (FELIX-1627) to use Ant properties, then System properties, then Environment variables. Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldFactory.java felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ant/BundleTask.java Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldFactory.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldFactory.java?rev=819912&r1=819911&r2=819912&view=diff ============================================================================== --- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldFactory.java (original) +++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldFactory.java Tue Sep 29 12:58:05 2009 @@ -19,7 +19,6 @@ package org.apache.felix.sigil.config; - import java.io.File; import java.io.IOException; import java.net.URI; @@ -27,29 +26,29 @@ import java.util.Map; import java.util.Properties; - public class BldFactory { private static Map projects = new HashMap(); - - public static IBldProject getProject( URI uri ) throws IOException + public static IBldProject getProject(URI uri) throws IOException { - return getProject( uri, false ); + return load(uri, false, null); } - - public static IBldProject getProject( URI uri, boolean ignoreCache ) throws IOException + public static IBldProject getProject(URI uri, Properties overrides) throws IOException { - return load( uri, ignoreCache ); + return load(uri, false, overrides); } - - public static IRepositoryConfig getConfig( URI uri ) throws IOException + public static IBldProject getProject(URI uri, boolean ignoreCache) throws IOException { - return load( uri, false ); + return load(uri, ignoreCache, null); } + public static IRepositoryConfig getConfig(URI uri) throws IOException + { + return load(uri, false, null); + } /** * creates a new project file, initialised with defaults. @@ -58,36 +57,35 @@ * @return * @throws IOException */ - public static IBldProject newProject( URI uri, String defaults ) throws IOException + public static IBldProject newProject(URI uri, String defaults) throws IOException { - BldProject project = new BldProject( uri ); + BldProject project = new BldProject(uri, null); Properties p = new Properties(); - if ( defaults != null ) - p.setProperty( BldConfig.S_DEFAULTS, defaults ); - project.loadDefaults( p ); + if (defaults != null) + p.setProperty(BldConfig.S_DEFAULTS, defaults); + project.loadDefaults(p); return project; } - - private static BldProject load( URI uri, boolean ignoreCache ) throws IOException + private static BldProject load(URI uri, boolean ignoreCache, Properties overrides) throws IOException { BldProject p = null; - if ( !ignoreCache ) + if (!ignoreCache) { - p = projects.get( uri ); + p = projects.get(uri); } - if ( p == null ) + if (p == null) { - p = new BldProject( uri ); + p = new BldProject(uri, overrides); p.load(); - projects.put( uri, p ); + projects.put(uri, p); - if ( Boolean.getBoolean( "org.apache.felix.sigil.config.test" ) ) + if (Boolean.getBoolean("org.apache.felix.sigil.config.test")) { - File path = new File( uri.getPath() + ".tmp" ); - System.out.println( "XXX: config.test writing: " + path ); - p.saveAs( path ); + File path = new File(uri.getPath() + ".tmp"); + System.out.println("XXX: config.test writing: " + path); + p.saveAs(path); } } return p; Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java?rev=819912&r1=819911&r2=819912&view=diff ============================================================================== --- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java (original) +++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java Tue Sep 29 12:58:05 2009 @@ -61,8 +61,9 @@ private static final int MAX_HEADER = 10240; // cache to avoid loading the same default config for each project private static Map defaultsCache = new HashMap(); - private static Properties overrides; + private static Properties sysOverrides; + private Properties bldOverrides; private List sourcePkgs; private BldConfig config; private BldConverter convert; @@ -73,7 +74,7 @@ private TreeSet packageWildDefaults; private long lastModified; - /* package */BldProject(URI relLoc) + /* package */BldProject(URI relLoc, Properties overrides) { config = new BldConfig(); convert = new BldConverter(config); @@ -81,6 +82,7 @@ File f = new File(loc); lastModified = f.lastModified(); baseDir = f.getParentFile(); + bldOverrides = overrides; } /* package */void load() throws IOException @@ -158,7 +160,7 @@ if (defaults != null) { - defaults = BldUtil.expand(defaults, new BldProperties(base)); + defaults = BldUtil.expand(defaults, new BldProperties(base, bldOverrides)); } else { @@ -176,7 +178,7 @@ { File file = new File(base, defaults).getCanonicalFile(); URL url = file.toURL(); - BldProperties bp = new BldProperties(file.getParentFile()); + BldProperties bp = new BldProperties(file.getParentFile(), bldOverrides); if (dflt == null) { @@ -230,9 +232,9 @@ private static Properties getOverrides() { - if (overrides == null) + if (sysOverrides == null) { - overrides = new Properties(); + sysOverrides = new Properties(); Properties sysProps = System.getProperties(); for (Object okey : sysProps.keySet()) @@ -240,13 +242,13 @@ String key = (String) okey; if (key.startsWith(OVERRIDE_PREFIX)) { - overrides.setProperty(key.substring(OVERRIDE_PREFIX.length()), + sysOverrides.setProperty(key.substring(OVERRIDE_PREFIX.length()), sysProps.getProperty(key)); } } } - return overrides; + return sysOverrides; } private void readHeader(InputStream in) throws IOException @@ -621,7 +623,7 @@ public Map getRepositoryConfig() { HashMap map = new HashMap(); - BldProperties bp = new BldProperties(baseDir); + BldProperties bp = new BldProperties(baseDir, bldOverrides); for (String name : config.getList(null, BldConfig.C_REPOSITORIES)) { Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java?rev=819912&r1=819911&r2=819912&view=diff ============================================================================== --- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java (original) +++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java Tue Sep 29 12:58:05 2009 @@ -26,7 +26,7 @@ public class BldProperties extends Properties { private static final long serialVersionUID = 1L; - private static final BldProperties global = new BldProperties(null); + private static final BldProperties global = new BldProperties(null, null); private static final Properties sysEnv; static @@ -40,10 +40,15 @@ private final Properties mySysEnv; - BldProperties(File baseDir) + BldProperties(File baseDir, Properties overrides) { mySysEnv = new Properties(sysEnv); + if (overrides != null) + { + mySysEnv.putAll(overrides); + } + try { if (baseDir != null) Modified: felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ant/BundleTask.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ant/BundleTask.java?rev=819912&r1=819911&r2=819912&view=diff ============================================================================== --- felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ant/BundleTask.java (original) +++ felix/trunk/sigil/ivy/resolver/src/org/apache/felix/sigil/ant/BundleTask.java Tue Sep 29 12:58:05 2009 @@ -19,7 +19,6 @@ package org.apache.felix.sigil.ant; - import java.io.File; import java.io.IOException; import java.net.URI; @@ -36,7 +35,6 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Path; - public class BundleTask extends Task { private File[] classpath; @@ -45,66 +43,66 @@ private String property; private String sigilFile; - @Override public void execute() throws BuildException { - if ( classpath == null ) - throw new BuildException( "missing: attribute: classpathref" ); - if ( destPattern == null ) - throw new BuildException( "missing attribute: destpattern" ); + if (classpath == null) + throw new BuildException("missing: attribute: classpathref"); + if (destPattern == null) + throw new BuildException("missing attribute: destpattern"); - IBldProject project; + @SuppressWarnings("unchecked") + Hashtable projectProperties = getProject().getProperties(); + Properties antProperties = new Properties(); + antProperties.putAll(projectProperties); + IBldProject project; try { - project = BldFactory.getProject( getSigilFileURI() ); - + project = BldFactory.getProject(getSigilFileURI(), antProperties); } - catch ( IOException e ) + catch (IOException e) { - throw new BuildException( "failed to get project file: " + e ); + throw new BuildException("failed to get project file: " + e); } Properties env = new Properties(); - @SuppressWarnings("unchecked") - Hashtable properties = getProject().getProperties(); - for ( String key : properties.keySet() ) + for (String key : projectProperties.keySet()) { - if ( key.matches( "^[a-z].*" ) ) + if (key.matches("^[a-z].*")) { // avoid props starting with Uppercase - bnd adds them to manifest - env.setProperty( key, properties.get( key ) ); + env.setProperty(key, projectProperties.get(key)); } } - BundleBuilder bb = new BundleBuilder( project, classpath, destPattern, env ); + BundleBuilder bb = new BundleBuilder(project, classpath, destPattern, env); boolean anyModified = false; - for ( IBldBundle bundle : project.getBundles() ) + for (IBldBundle bundle : project.getBundles()) { String id = bundle.getId(); - log( "creating bundle: " + id ); + log("creating bundle: " + id); int nWarn = 0; int nErr = 0; String msg = ""; try { - boolean modified = ( bb.createBundle( bundle, force, new BundleBuilder.Log() - { - public void warn( String msg ) + boolean modified = (bb.createBundle(bundle, force, + new BundleBuilder.Log() { - log( msg, Project.MSG_WARN ); - } - - - public void verbose( String msg ) - { - log( msg, Project.MSG_VERBOSE ); - } - } ) ); + public void warn(String msg) + { + log(msg, Project.MSG_WARN); + } + + public void verbose(String msg) + { + log(msg, Project.MSG_VERBOSE); + } + })); nWarn = bb.warnings().size(); - if ( modified ) + if (modified) { anyModified = true; } @@ -113,86 +111,80 @@ msg = " (not modified)"; } } - catch ( Exception e ) + catch (Exception e) { List errors = bb.errors(); - if ( errors != null ) + if (errors != null) { nErr = errors.size(); - for ( String err : errors ) + for (String err : errors) { - log( err, Project.MSG_ERR ); + log(err, Project.MSG_ERR); } } - throw new BuildException( "failed to create: " + id + ": " + e, e ); + throw new BuildException("failed to create: " + id + ": " + e, e); } finally { - log( id + ": " + count( nErr, "error" ) + ", " + count( nWarn, "warning" ) + msg ); + log(id + ": " + count(nErr, "error") + ", " + count(nWarn, "warning") + + msg); } } - if ( anyModified && property != null ) + if (anyModified && property != null) { - getProject().setProperty( property, "true" ); + getProject().setProperty(property, "true"); } } - private URI getSigilFileURI() { - File file = sigilFile == null ? new File( getProject().getBaseDir(), IBldProject.PROJECT_FILE ) : new File( - sigilFile ); - if ( !file.isFile() ) + File file = sigilFile == null ? new File(getProject().getBaseDir(), + IBldProject.PROJECT_FILE) : new File(sigilFile); + if (!file.isFile()) { - throw new BuildException( "File not found " + file.getAbsolutePath() ); + throw new BuildException("File not found " + file.getAbsolutePath()); } return file.toURI(); } - - private String count( int count, String msg ) + private String count(int count, String msg) { - return count + " " + msg + ( count == 1 ? "" : "s" ); + return count + " " + msg + (count == 1 ? "" : "s"); } - - public void setDestpattern( String pattern ) + public void setDestpattern(String pattern) { this.destPattern = pattern; } - - public void setForce( String force ) + public void setForce(String force) { - this.force = Boolean.parseBoolean( force ); + this.force = Boolean.parseBoolean(force); } - - public void setProperty( String property ) + public void setProperty(String property) { this.property = property; } - - public void setClasspathref( String value ) + public void setClasspathref(String value) { - Path p = ( Path ) getProject().getReference( value ); - if ( p == null ) + Path p = (Path) getProject().getReference(value); + if (p == null) { - throw new BuildException( value + "is not a path reference." ); + throw new BuildException(value + "is not a path reference."); } String[] paths = p.list(); classpath = new File[paths.length]; - for ( int i = 0; i < paths.length; ++i ) + for (int i = 0; i < paths.length; ++i) { - classpath[i] = new File( paths[i] ); + classpath[i] = new File(paths[i]); } } - - public void setSigilFile( String sigilFile ) + public void setSigilFile(String sigilFile) { this.sigilFile = sigilFile; }