From 3dca89f0015613ab3f287945965e9f92a6079cd8 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Tue, 6 Oct 2009 14:44:29 +0200 Subject: Reformat all source files and add licenses to tests --- .../java/org/apache/maven/plugin/nar/NarInfo.java | 331 +++++++++++---------- 1 file changed, 180 insertions(+), 151 deletions(-) (limited to 'src/main/java/org/apache/maven/plugin/nar/NarInfo.java') diff --git a/src/main/java/org/apache/maven/plugin/nar/NarInfo.java b/src/main/java/org/apache/maven/plugin/nar/NarInfo.java index 1074104..a6d2861 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarInfo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarInfo.java @@ -19,7 +19,6 @@ package org.apache.maven.plugin.nar; * under the License. */ - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -32,156 +31,186 @@ import java.util.jar.JarFile; import org.apache.maven.plugin.logging.Log; /** - * * @author Mark Donszelmann */ -public class NarInfo { - - public static final String NAR_PROPERTIES = "nar.properties"; - private String groupId, artifactId, version; - private Properties info; - private Log log; - - public NarInfo(String groupId, String artifactId, String version, Log log) { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.log = log; - info = new Properties(); - - // Fill with general properties.nar file - File propertiesDir = new File("src/main/resources/META-INF/nar/" - + groupId + "/" + artifactId); - if (!propertiesDir.exists()) { - propertiesDir.mkdirs(); - } - File propertiesFile = new File(propertiesDir, NarInfo.NAR_PROPERTIES); - try { - info.load(new FileInputStream(propertiesFile)); - } catch (IOException ioe) { - // ignored - } - - } - - public String toString() { - StringBuffer s = new StringBuffer("NarInfo for "); - s.append(groupId); - s.append(":"); - s.append(artifactId); - s.append("-"); - s.append(version); - s.append(" {\n"); - - for (Iterator i = info.keySet().iterator(); i.hasNext();) { - String key = (String) i.next(); - s.append(" "); - s.append(key); - s.append("='"); - s.append(info.getProperty(key, "")); - s.append("'\n"); - } - - s.append("}\n"); - return s.toString(); - } - - public boolean exists(JarFile jar) { - return getNarPropertiesEntry(jar) != null; - } - - public void read(JarFile jar) throws IOException { - info.load(jar.getInputStream(getNarPropertiesEntry(jar))); - } - - private JarEntry getNarPropertiesEntry(JarFile jar) { - return jar.getJarEntry("META-INF/nar/" + groupId + "/" + artifactId - + "/" + NAR_PROPERTIES); - } - - /** - * No binding means default binding. - * - * @param aol - * @return - */ - public String getBinding(AOL aol, String defaultBinding) { - return getProperty(aol, "libs.binding", defaultBinding); - } - - public void setBinding(AOL aol, String value) { - setProperty(aol, "libs.binding", value); - } - - // FIXME replace with list of AttachedNarArtifacts - public String[] getAttachedNars(AOL aol, String type) { - String attachedNars = getProperty(aol, "nar." + type); - return attachedNars != null ? attachedNars.split(",") : null; - } - - public void addNar(AOL aol, String type, String nar) { - String nars = getProperty(aol, "nar." + type); - nars = (nars == null) ? nar : nars + ", " + nar; - setProperty(aol, "nar." + type, nars); - } - - public void setNar(AOL aol, String type, String nar) { - setProperty(aol, "nar." + type, nar); - } - - public AOL getAOL(AOL aol) { - return aol == null ? null : new AOL(getProperty(aol, aol.toString(), aol.toString())); - } - - public String getOptions(AOL aol) { - return getProperty(aol, "linker.options"); - } - - public String getLibs(AOL aol) { - return getProperty(aol, "libs.names", artifactId + "-" + version); - } - - public String getSysLibs(AOL aol) { - return getProperty(aol, "syslibs.names"); - } - - public void writeToFile(File file) throws IOException { - info.store(new FileOutputStream((file)), "NAR Properties for " - + groupId + "." + artifactId + "-" + version); - } - - private void setProperty(AOL aol, String key, String value) { - if (aol == null) { - info.setProperty(key, value); - } else { - info.setProperty(aol.toString() + "." + key, value); - } - } - - public String getProperty(AOL aol, String key) { - return getProperty(aol, key, (String)null); - } - - public String getProperty(AOL aol, String key, String defaultValue) { - if (key == null) - return defaultValue; - String value = info.getProperty(key, defaultValue); - value = aol == null ? value : info.getProperty(aol.toString() + "." - + key, value); - log.debug("getProperty(" + aol + ", " + key + ", " - + defaultValue + ") = " + value); - return value; - } - - public int getProperty(AOL aol, String key, int defaultValue) { - return Integer.parseInt(getProperty(aol, key, Integer.toString(defaultValue))); - } - - public boolean getProperty(AOL aol, String key, boolean defaultValue) { - return Boolean.parseBoolean(getProperty(aol, key, String.valueOf(defaultValue))); - } - - public File getProperty(AOL aol, String key, File defaultValue) { - return new File(getProperty(aol, key, defaultValue.getPath())); - } +public class NarInfo +{ + + public static final String NAR_PROPERTIES = "nar.properties"; + + private String groupId, artifactId, version; + + private Properties info; + + private Log log; + + public NarInfo( String groupId, String artifactId, String version, Log log ) + { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.log = log; + info = new Properties(); + + // Fill with general properties.nar file + File propertiesDir = new File( "src/main/resources/META-INF/nar/" + groupId + "/" + artifactId ); + if ( !propertiesDir.exists() ) + { + propertiesDir.mkdirs(); + } + File propertiesFile = new File( propertiesDir, NarInfo.NAR_PROPERTIES ); + try + { + info.load( new FileInputStream( propertiesFile ) ); + } + catch ( IOException ioe ) + { + // ignored + } + + } + + public String toString() + { + StringBuffer s = new StringBuffer( "NarInfo for " ); + s.append( groupId ); + s.append( ":" ); + s.append( artifactId ); + s.append( "-" ); + s.append( version ); + s.append( " {\n" ); + + for ( Iterator i = info.keySet().iterator(); i.hasNext(); ) + { + String key = (String) i.next(); + s.append( " " ); + s.append( key ); + s.append( "='" ); + s.append( info.getProperty( key, "" ) ); + s.append( "'\n" ); + } + + s.append( "}\n" ); + return s.toString(); + } + + public boolean exists( JarFile jar ) + { + return getNarPropertiesEntry( jar ) != null; + } + + public void read( JarFile jar ) + throws IOException + { + info.load( jar.getInputStream( getNarPropertiesEntry( jar ) ) ); + } + + private JarEntry getNarPropertiesEntry( JarFile jar ) + { + return jar.getJarEntry( "META-INF/nar/" + groupId + "/" + artifactId + "/" + NAR_PROPERTIES ); + } + + /** + * No binding means default binding. + * + * @param aol + * @return + */ + public String getBinding( AOL aol, String defaultBinding ) + { + return getProperty( aol, "libs.binding", defaultBinding ); + } + + public void setBinding( AOL aol, String value ) + { + setProperty( aol, "libs.binding", value ); + } + + // FIXME replace with list of AttachedNarArtifacts + public String[] getAttachedNars( AOL aol, String type ) + { + String attachedNars = getProperty( aol, "nar." + type ); + return attachedNars != null ? attachedNars.split( "," ) : null; + } + + public void addNar( AOL aol, String type, String nar ) + { + String nars = getProperty( aol, "nar." + type ); + nars = ( nars == null ) ? nar : nars + ", " + nar; + setProperty( aol, "nar." + type, nars ); + } + + public void setNar( AOL aol, String type, String nar ) + { + setProperty( aol, "nar." + type, nar ); + } + + public AOL getAOL( AOL aol ) + { + return aol == null ? null : new AOL( getProperty( aol, aol.toString(), aol.toString() ) ); + } + + public String getOptions( AOL aol ) + { + return getProperty( aol, "linker.options" ); + } + + public String getLibs( AOL aol ) + { + return getProperty( aol, "libs.names", artifactId + "-" + version ); + } + + public String getSysLibs( AOL aol ) + { + return getProperty( aol, "syslibs.names" ); + } + + public void writeToFile( File file ) + throws IOException + { + info.store( new FileOutputStream( ( file ) ), "NAR Properties for " + groupId + "." + artifactId + "-" + + version ); + } + + private void setProperty( AOL aol, String key, String value ) + { + if ( aol == null ) + { + info.setProperty( key, value ); + } + else + { + info.setProperty( aol.toString() + "." + key, value ); + } + } + + public String getProperty( AOL aol, String key ) + { + return getProperty( aol, key, (String) null ); + } + + public String getProperty( AOL aol, String key, String defaultValue ) + { + if ( key == null ) + return defaultValue; + String value = info.getProperty( key, defaultValue ); + value = aol == null ? value : info.getProperty( aol.toString() + "." + key, value ); + log.debug( "getProperty(" + aol + ", " + key + ", " + defaultValue + ") = " + value ); + return value; + } + + public int getProperty( AOL aol, String key, int defaultValue ) + { + return Integer.parseInt( getProperty( aol, key, Integer.toString( defaultValue ) ) ); + } + + public boolean getProperty( AOL aol, String key, boolean defaultValue ) + { + return Boolean.parseBoolean( getProperty( aol, key, String.valueOf( defaultValue ) ) ); + } + + public File getProperty( AOL aol, String key, File defaultValue ) + { + return new File( getProperty( aol, key, defaultValue.getPath() ) ); + } } -- cgit v1.2.3