Moin Henrique,
I'm having problems applying the patch. Please send me the modified
files.
Uli
Am 27.03.2007 um 03:57 schrieb Henrique Prange:
> Hi Andrus and Ulrich,
>
> I have corrected the following problems on maven-wolifecycle-plugin:
>
> -webobjects\apple is not considered a webobjects group (only on
> Windows)
> -Incorrect localRepository (only on Windows)
> -Dependencies with scope = provided is added to the final WOA
> (WOL-394)
> -Problem with localized resources (reported by Fabian)
>
> The patch is attached.
>
> I've created some tests. It would be interesting to execute them to
> verify if they work on Mac.
>
> Cheers,
>
> Henrique
>
> --
>
> \o/ Henrique Prange, Moleque de Idéias Educaçăo e Tecnologia Ltda
> | Phone: 55-21-2710-0178 E-mail: hprang..oleque.com.br
> / \ http://www.moleque.com.br
> Index: .classpath
> ===================================================================
> --- .classpath (revision 3898)
> +++ .classpath (working copy)
>.. -1,9 +1,10 @@
> -<?xml version="1.0" encoding="UTF-8"?>
> -<classpath>
> - <classpathentry kind="src" path="src/main/java"/>
> - <classpathentry kind="src" path="src/main/scripts"/>
> - <classpathentry kind="src" path="src/main/resources"/>
> - <classpathentry kind="con"
> path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
> - <classpathentry kind="con"
> path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
> - <classpathentry kind="output" path="bin"/>
> -</classpath>
> +<?xml version="1.0" encoding="UTF-8"?>
> +<classpath>
> + <classpathentry kind="src" path="src/main/java"/>
> + <classpathentry kind="src" path="src/test/java"/>
> + <classpathentry kind="src" path="src/main/scripts"/>
> + <classpathentry kind="src" path="src/main/resources"/>
> + <classpathentry kind="con"
> path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
> + <classpathentry kind="con"
> path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
> + <classpathentry kind="output" path="bin"/>
> +</classpath>
> Index: src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> DefineResourcesMojo.java
> ===================================================================
> --- src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> DefineResourcesMojo.java (revision 3898)
> +++ src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> DefineResourcesMojo.java (working copy)
>.. -189,7 +189,7 @@
> if (fileName.equalsIgnoreCase("Nonlocalized.lproj")) {
> resource.setTargetPath(fullTargetPath);
> } else {
> - resource.setTargetPath(fullTargetPath + File.separator +
> fileName.substring(0, fileName.length() - 6));
> + resource.setTargetPath(fullTargetPath + File.separator +
> fileName);
> }
> resources.add(resource);
> }
> Index: src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> DefineWOApplicationResourcesMojo.java
> ===================================================================
> --- src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> DefineWOApplicationResourcesMojo.java (revision 3898)
> +++ src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> DefineWOApplicationResourcesMojo.java (working copy)
>.. -18,6 +18,7 @@
> import java.util.jar.JarFile;
> import java.util.jar.JarInputStream;
>
> +import org.apache.commons.io.FilenameUtils;
> import org.apache.maven.artifact.Artifact;
> import org.apache.maven.artifact.factory.ArtifactFactory;
> import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
>.. -43,27 +44,21 @@
> public class DefineWOApplicationResourcesMojo extends
> DefineResourcesMojo {
>
> /**
> - * The maven project.
> + * Changes back slashes '\' on Windows to '/'.
> *
> - *..arameter expression="${project}"
> - *..equired
> - *..eadonly
> + *..aram path
> + * Any file path
> + *..eturn Returns a file path without back slashes
> */
> - private MavenProject project;
> -
> - /**
> - *..arameter expression="${localRepository}"
> - *..equired
> - *..eadonly
> - */
> - private ArtifactRepository localRepository;
> + public static String normalizedPath(String path) {
> + return FilenameUtils.separatorsToUnix(path);
> + }
>
> /**
> - * Read patternsets.
> *
> - *..arameter expression="readPatternsets"
> + *..omponent
> */
> - private Boolean readPatternsets;
> + private ArtifactFactory artifactFactory;
>
> /**
> *..omponent
>.. -70,11 +65,21 @@
> */
> private ArtifactResolver artifactResolver;
>
> + private String[][] dependencyPaths;
> +
> /**
> + * include JavaClientClasses in WebServerResources.
> *
> - *..omponent
> + *..arameter
> expression="includeJavaClientClassesInWebServerResources"
> */
> - private ArtifactFactory artifactFactory;
> + private Boolean includeJavaClientClassesInWebServerResources;
> +
> + /**
> + *..arameter expression="${localRepository}"
> + *..equired
> + *..eadonly
> + */
> + private ArtifactRepository localRepository;
>
> /**
> *
>.. -83,19 +88,26 @@
> private ArtifactMetadataSource metadataSource;
>
> /**
> + * The maven project.
> *
> - *..arameter expression="${project.remoteArtifactRepositories}"
> + *..arameter expression="${project}"
> + *..equired
> + *..eadonly
> */
> - private List remoteRepositories;
> + private MavenProject project;
>
> - private String[][] dependencyPaths;
> + /**
> + * Read patternsets.
> + *
> + *..arameter expression="readPatternsets"
> + */
> + private Boolean readPatternsets;
>
> /**
> - * include JavaClientClasses in WebServerResources.
> *
> - *..arameter
> expression="includeJavaClientClassesInWebServerResources"
> + *..arameter expression="${project.remoteArtifactRepositories}"
> */
> - private Boolean includeJavaClientClassesInWebServerResources;
> + private List remoteRepositories;
>
> /**
> * skip webobjects frameworks from apple.
>.. -108,54 +120,6 @@
> super();
> }
>
> - public void execute() throws MojoExecutionException,
> MojoFailureException {
> - super.execute();
> - try {
> - this.defineProperties();
> - this.defineClasspath();
> - this.executeCopyWebServerResources();
> - } finally {
> - dependencyPaths = null;
> - }
> - }
> -
> - private void executeCopyWebServerResources() throws
> MojoExecutionException {
> - getLog().info("Copy webserverresources");
> - String[][] classpathEntries = this.getDependencyPaths();
> - for (int i = 0; i < classpathEntries[1].length; i++) {
> - if (skipAppleProvidedFrameworks != null &&
> skipAppleProvidedFrameworks.booleanValue() &&
> this.isWebobjectAppleGroup(classpathEntries[2][i])) {
> - getLog().debug("Defining wo classpath: dependencyPath: " +
> classpathEntries[0][i] + "is in the apple group skipping");
> - continue;
> - }
> - FileInputStream fileInputStream;
> - try {
> - String jarFileName = localRepository.getBasedir() +
> File.separator + classpathEntries[0][i];
> - getLog().debug("Copy webserverresources: looking into jar
> named " + jarFileName);
> - fileInputStream = new FileInputStream(jarFileName);
> - JarInputStream jarInputStream = new JarInputStream
> (fileInputStream);
> - int counter = 0;
> - JarEntry jarEntry = null;
> - while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
> - if (!jarEntry.isDirectory()) {
> - String jarEntryName = jarEntry.getName();
> - String prefix = "WebServerResources";
> - String frameworksFolderName = this.getProjectFolder() +
> "target" + File.separator + this.getProject().getArtifactId() + "-"
> + this.getProject().getVersion() + ".woa" + File.separator +
> "Contents" + File.separator + "Frameworks" + File.separator;
> - if (jarEntryName != null && jarEntryName.length() >
> prefix.length() && jarEntryName.startsWith(prefix)) {
> - File destinationFolder = new File(frameworksFolderName +
> classpathEntries[1][i] + ".framework");
> - this.copyJarEntryToFile(jarFileName, destinationFolder,
> jarEntry);
> - counter++;
> - }
> - }
> - }
> - getLog().debug("Copy webserverresources: extracted " + counter
> + " webserverresources from jar named " + jarFileName);
> - } catch (FileNotFoundException e) {
> - throw new MojoExecutionException("Could not open file input
> stream", e);
> - } catch (IOException e) {
> - throw new MojoExecutionException("Could not open jar input
> stream", e);
> - }
> - }
> - }
> -
> private void copyJarEntryToFile(String jarFileName, File
> destinationFolder, JarEntry jarEntry) throws IOException,
> FileNotFoundException {
> // getLog().info("Copy webserverresources: jarFileName " +
> jarFileName +
> // " destinationFolder " + destinationFolder);
>.. -203,21 +167,6 @@
> }
> }
>
> - private void defineProperties() throws MojoExecutionException {
> - String fileName = this.getProjectFolder() + "target" +
> File.separator + "wobuild.properties";
> - getLog().debug("Defining wo properties: writing to file: " +
> fileName);
> - File file = new File(fileName);
> - FileWriter fileWriter;
> - try {
> - fileWriter = new FileWriter(file);
> - fileWriter.write("maven.localRepository.baseDir = " +
> localRepository.getBasedir());
> - fileWriter.flush();
> - fileWriter.close();
> - } catch (IOException e) {
> - throw new MojoExecutionException("Could not write wo
> properties", e);
> - }
> - }
> -
> private void defineClasspath() throws MojoExecutionException {
> getLog().debug("Defining wo classpath: dependencies from
> parameter");
> String[][] classpathEntries = this.getDependencyPaths();
>.. -225,10 +174,10 @@
> for (int k = 0; k < 2; k++) {
> for (int i = 0; i < classpathEntries[0].length; i++) {
> getLog().debug("Defining wo classpath: dependencyPath: " +
> classpathEntries[0][i]);
> - if(k== 0 && this.isWebobjectAppleGroup(classpathEntries[2][i])) {
> + if (k == 0 && this.isWebobjectAppleGroup(classpathEntries[2]
> [i])) {
> continue;
> }
> - if(k== 1 && !this.isWebobjectAppleGroup(classpathEntries[2]
> [i])) {
> + if (k == 1 && !this.isWebobjectAppleGroup(classpathEntries[2]
> [i])) {
> continue;
> }
> if (skipAppleProvidedFrameworks != null &&
> skipAppleProvidedFrameworks.booleanValue() &&
> this.isWebobjectAppleGroup(classpathEntries[2][i])) {
>.. -252,20 +201,67 @@
> }
> }
>
> - public MavenProject getProject() {
> - return project;
> + private void defineProperties() throws MojoExecutionException {
> + String fileName = this.getProjectFolder() + "target" +
> File.separator + "wobuild.properties";
> + getLog().debug("Defining wo properties: writing to file: " +
> fileName);
> + File file = new File(fileName);
> + FileWriter fileWriter;
> + try {
> + fileWriter = new FileWriter(file);
> + fileWriter.write("maven.localRepository.baseDir = " +
> normalizedPath(localRepository.getBasedir()));
> + fileWriter.flush();
> + fileWriter.close();
> + } catch (IOException e) {
> + throw new MojoExecutionException("Could not write wo
> properties", e);
> + }
> }
>
> - public String getProductExtension() {
> - return "woa";
> + public void execute() throws MojoExecutionException,
> MojoFailureException {
> + super.execute();
> + try {
> + this.defineProperties();
> + this.defineClasspath();
> + this.executeCopyWebServerResources();
> + } finally {
> + dependencyPaths = null;
> + }
> }
>
> - public boolean hasContentsFolder() {
> - return true;
> - }
> -
> - protected Boolean readPatternsets() {
> - return readPatternsets;
> + private void executeCopyWebServerResources() throws
> MojoExecutionException {
> + getLog().info("Copy webserverresources");
> + String[][] classpathEntries = this.getDependencyPaths();
> + for (int i = 0; i < classpathEntries[1].length; i++) {
> + if (skipAppleProvidedFrameworks != null &&
> skipAppleProvidedFrameworks.booleanValue() &&
> this.isWebobjectAppleGroup(classpathEntries[2][i])) {
> + getLog().debug("Defining wo classpath: dependencyPath: " +
> classpathEntries[0][i] + "is in the apple group skipping");
> + continue;
> + }
> + FileInputStream fileInputStream;
> + try {
> + String jarFileName = localRepository.getBasedir() +
> File.separator + classpathEntries[0][i];
> + getLog().debug("Copy webserverresources: looking into jar
> named " + jarFileName);
> + fileInputStream = new FileInputStream(jarFileName);
> + JarInputStream jarInputStream = new JarInputStream
> (fileInputStream);
> + int counter = 0;
> + JarEntry jarEntry = null;
> + while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
> + if (!jarEntry.isDirectory()) {
> + String jarEntryName = jarEntry.getName();
> + String prefix = "WebServerResources";
> + String frameworksFolderName = this.getProjectFolder() +
> "target" + File.separator + this.getProject().getArtifactId() + "-"
> + this.getProject().getVersion() + ".woa" + File.separator +
> "Contents" + File.separator + "Frameworks" + File.separator;
> + if (jarEntryName != null && jarEntryName.length() >
> prefix.length() && jarEntryName.startsWith(prefix)) {
> + File destinationFolder = new File(frameworksFolderName +
> classpathEntries[1][i] + ".framework");
> + this.copyJarEntryToFile(jarFileName, destinationFolder,
> jarEntry);
> + counter++;
> + }
> + }
> + }
> + getLog().debug("Copy webserverresources: extracted " + counter
> + " webserverresources from jar named " + jarFileName);
> + } catch (FileNotFoundException e) {
> + throw new MojoExecutionException("Could not open file input
> stream", e);
> + } catch (IOException e) {
> + throw new MojoExecutionException("Could not open jar input
> stream", e);
> + }
> + }
> }
>
> private String[][] getDependencyPaths() throws
> MojoExecutionException {
>.. -291,6 +287,11 @@
> Iterator dependenciesIterator = artifacts.iterator();
> while (dependenciesIterator.hasNext()) {
> Artifact artifact = (Artifact) dependenciesIterator.next();
> +
> + if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
> + continue;
> + }
> +
> String depenendencyGroup = artifact.getGroupId();
> if (depenendencyGroup != null) {
> depenendencyGroup = depenendencyGroup.replace('.',
> File.separatorChar);
>.. -314,7 +315,23 @@
> return dependencyPaths;
> }
>
> + public String getProductExtension() {
> + return "woa";
> + }
> +
> + public MavenProject getProject() {
> + return project;
> + }
> +
> + public boolean hasContentsFolder() {
> + return true;
> + }
> +
> public boolean includesVersionInArtifactName() {
> return true;
> }
> +
> + protected Boolean readPatternsets() {
> + return readPatternsets;
> + }
> }
> Index: src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> WOMojo.java
> ===================================================================
> --- src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> WOMojo.java (revision 3898)
> +++ src/main/java/org/objectstyle/woproject/maven2/wolifecycle/
> WOMojo.java (working copy)
>.. -3,6 +3,7 @@
> //org.apache.maven.plugins:maven-compiler-plugin:compile
> import java.io.File;
>
> +import org.apache.commons.io.FilenameUtils;
> import org.apache.maven.plugin.AbstractMojo;
> import org.apache.maven.project.MavenProject;
>
>.. -14,18 +15,14 @@
> super();
> }
>
> - protected boolean isWebobjectAppleGroup(String dependencyGroup) {
> - boolean returnValue = false;
> - if (dependencyGroup != null) {
> - if(dependencyGroup.indexOf('.') >= 0) {
> - throw new IllegalStateException();
> - }
> - returnValue = dependencyGroup.equals(MAVEN_WEBOBJECTS_GROUP_ID);
> - }
> - getLog().debug("WOMojo: isWebobjectAppleGroup: " +
> dependencyGroup + " return value " + returnValue);
> - return returnValue;
> + private boolean containsDot(String text) {
> + return text.indexOf('.') >= 0;
> }
>
> + public abstract String getProductExtension();
> +
> + public abstract MavenProject getProject();
> +
> protected String getProjectFolder() {
> String projectFolder = this.getProject().getFile().getPath
> ().substring(0, this.getProject().getFile().getPath().length() - 7);
> return projectFolder;
>.. -39,7 +36,21 @@
> return null;
> }
>
> - public abstract String getProductExtension();
> + protected boolean isWebobjectAppleGroup(String dependencyGroup) {
> + if (dependencyGroup == null) {
> + return false;
> + }
>
> - public abstract MavenProject getProject();
> + if (containsDot(dependencyGroup)) {
> + throw new IllegalArgumentException("Dependency group cannot
> contains '.' (dot).");
> + }
> +
> + String normalizedGroup = FilenameUtils.separatorsToUnix
> (dependencyGroup);
> +
> + boolean returnValue = MAVEN_WEBOBJECTS_GROUP_ID.equals
> (normalizedGroup);
> +
> + getLog().debug("WOMojo: isWebobjectAppleGroup: " +
> normalizedGroup + " return value " + returnValue);
> +
> + return returnValue;
> + }
> }
> Index: src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> MockWOMojo.java
> ===================================================================
> --- src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> MockWOMojo.java
> +++ src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> MockWOMojo.java
>.. -0,0 +1,25 @@
> +package org.objectstyle.woproject.maven2.wolifecycle;
> +
> +import org.apache.maven.plugin.MojoExecutionException;
> +import org.apache.maven.plugin.MojoFailureException;
> +import org.apache.maven.project.MavenProject;
> +
> +/**
> + * Only to test methods on abstract class
> + *
> + *..uthor <a href="mailto:hprange@moleque.com.br">Henrique
> Prange</a>
> + */
> +public class MockWOMojo extends WOMojo {
> +
> + public String getProductExtension() {
> + return null;
> + }
> +
> + public MavenProject getProject() {
> + return null;
> + }
> +
> + public void execute() throws MojoExecutionException,
> MojoFailureException {
> + // Do nothing
> + }
> +}
> Index: src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> TestDefineWOApplicationResourcesMojo.java
> ===================================================================
> --- src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> TestDefineWOApplicationResourcesMojo.java
> +++ src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> TestDefineWOApplicationResourcesMojo.java
>.. -0,0 +1,13 @@
> +package org.objectstyle.woproject.maven2.wolifecycle;
> +
> +import junit.framework.TestCase;
> +
> +public class TestDefineWOApplicationResourcesMojo extends TestCase {
> + public void testNormalizedFilePath() throws Exception {
> + String path = "C:\\Documents and Settings\\User\\.m2\\repository";
> +
> + String result = DefineWOApplicationResourcesMojo.normalizedPath
> (path);
> +
> + assertEquals("C:/Documents and Settings/User/.m2/repository",
> result);
> + }
> +}
> Index: src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> TestWOMojo.java
> ===================================================================
> --- src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> TestWOMojo.java
> +++ src/test/java/org/objectstyle/woproject/maven2/wolifecycle/
> TestWOMojo.java
>.. -0,0 +1,49 @@
> +package org.objectstyle.woproject.maven2.wolifecycle;
> +
> +import junit.framework.TestCase;
> +
> +public class TestWOMojo extends TestCase {
> +
> + protected WOMojo mojo;
> +
> + protected void setUp() throws Exception {
> + super.setUp();
> +
> + mojo = new MockWOMojo();
> + }
> +
> + public void testIsInvalidGroup() throws Exception {
> + String groups[] = { ".invalidgroup", "invalid.group",
> "invalidgroup." };
> +
> + for (int i = 0; i < groups.length; i++) {
> + try {
> + mojo.isWebobjectAppleGroup(groups[i]);
> +
> + fail("Invalid group. Should throw an IllegalArgumentException.");
> + } catch (IllegalArgumentException exception) {
> + assertEquals("Dependency group cannot contains '.' (dot).",
> exception.getMessage());
> + }
> + }
> + }
> +
> + public void testIsNotWebObjectsGroup() throws Exception {
> + String group = "another/group";
> +
> + assertFalse(mojo.isWebobjectAppleGroup(group));
> + }
> +
> + public void testIsNullGroup() throws Exception {
> + assertFalse(mojo.isWebobjectAppleGroup(null));
> + }
> +
> + public void testWebObjectsGroupIsOsIndependent() throws Exception {
> + String group = "webobjects/apple";
> +
> + assertTrue(mojo.isWebobjectAppleGroup(group));
> +
> + group = "webobjects\\apple";
> +
> + assertTrue(mojo.isWebobjectAppleGroup(group));
> + }
> +
> +}
This archive was generated by hypermail 2.0.0 : Thu Apr 05 2007 - 04:14:36 EDT