qickrooms / flex-mojos

Automatically exported from code.google.com/p/flex-mojos
0 stars 0 forks source link

Change defines from map to properties #98

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
At present time defines are declared like this:
<configuration>
    <defines>
        <BUILD::version>1</BUILD::version>
    </defines>
</configuration>

But, XML doesn't handle well with two dots ':'

Changing from Map to Properties it will be declared like this:
<configuration>
    <defines>
        <define>
            <name>BUILD::version</name>
            <value>1</value>
        </define>
    </defines>
</configuration>

http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

Original issue reported on code.google.com by velo...@gmail.com on 29 Aug 2008 at 1:38

GoogleCodeExporter commented 9 years ago
On maven 3 I got this bizarre exception:

org.apache.maven.project.ProjectBuildingException: File =
D:\flex\workspace\sonatype-flex-mojos\test-harness\target\test-classes\issues\is
sue-0068\pom.xml
for project unknown
    at
org.apache.maven.project.DefaultMavenProjectBuilder.readModelFromLocalPath(Defau
ltMavenProjectBuilder.java:2093)
    at
org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(
DefaultMavenProjectBuilder.java:494)
    at
org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBui
lder.java:193)
    at org.apache.maven.DefaultMaven.build_aroundBody2(DefaultMaven.java:312)
    at org.apache.maven.DefaultMaven.build_aroundBody3$advice(DefaultMaven.java:447)
    at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:312)
    at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:282)
    at org.apache.maven.DefaultMaven.createReactorManager(DefaultMaven.java:103)
    at org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:160)
    at org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:303)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
    at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904)
    at
org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder
.java:303)
    at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
    at info.flexmojos.tests.AbstractFlexMojosTests.test(AbstractFlexMojosTests.java:76)
    at
info.rvin.mojo.flexmojo.test.IT0015CoverageTest.testDefines(IT0015CoverageTest.j
ava:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:87)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.
java:88)
    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(Abstra
ctDirectoryTestSuite.java:140)
    at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirec
toryTestSuite.java:127)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBoote
r.java:345)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: java.io.IOException: :com.ctc.wstx.exc.WstxUnexpectedCharException:
Unexpected character ':' (code 58) (missing namespace prefix?)
 at [row,col {unknown-source}]: [24,14]
    at
org.apache.maven.shared.model.ModelMarshaller.marshallXmlToModelProperties(Model
Marshaller.java:178)
    at
org.apache.maven.project.builder.PomClassicTransformer.transformToModelPropertie
s(PomClassicTransformer.java:186)
    at
org.apache.maven.shared.model.ModelTransformerContext.transform(ModelTransformer
Context.java:123)
    at
org.apache.maven.project.builder.impl.DefaultProjectBuilder.buildFromLocalPath(D
efaultProjectBuilder.java:157)
    at
org.apache.maven.project.DefaultMavenProjectBuilder.readModelFromLocalPath(Defau
ltMavenProjectBuilder.java:2088)
    ... 41 more

Original comment by velo...@gmail.com on 29 Aug 2008 at 6:06

GoogleCodeExporter commented 9 years ago
any news on this issue. i'm also using this defines , the normal build/deploy
cycle works but when i'm doing a release:prepare  i get this error :-(
..
INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error reading POM: Error on line 28: Element or attribute do not match 
QName 
production: QName::=(NCName':')?NCName.

my pom looks like this
<build>
 <plugins>
    <plugin>
       <groupId>info.flex-mojos</groupId>
       <artifactId>flex-compiler-mojo</artifactId>
       <extensions>true</extensions>
       <configuration>
          <defines>
            <VERSION::version>"${project.version}"</VERSION::version>
            <VERSION::revision>"${buildNumber}"</VERSION::revision>
            <VERSION::builduser>"${user.name}"</VERSION::builduser>
            <VERSION::buildtimestamp>"${timestamp}"</VERSION::buildtimestamp>
          </defines>
       </configuration>
     </plugin>

Original comment by luc.w...@gmail.com on 22 Oct 2008 at 11:26

GoogleCodeExporter commented 9 years ago
Ok , i tried the Map -> property conversion using 2.0M8-SNAPSHOT.
it is basicly working BUT there are some issues :

custom properties created by plugins like the buildNumber are not resolved.
when using Properties implementation of defines.

So i needed to do this in the code, and that looks somewhat "ugly"

This is the code i currently use :

@FlexCompatibility( minVersion = "3" )
    private void addDefines()
    {
        if ( defines != null )
        {
            Set<Object> keys=defines.keySet();
            Properties mvnproperties=project.getProperties();
            for ( Object k : keys )
            {
                String key=(String)k;
                String value = defines.getProperty(key);
                //replace any ${xxx} token with real value
                if (value.contains("${") ) {
                    //Ok here is the deal: if ${xxx} exist , than replace is 
with value.
                    //if it doesn't exist , replace with null because 
flex-compile doesn't like ${xxx} in defines
                    Pattern pattern = Pattern.compile("[\\\\$\\\\{\\.*\\\\}]+");
                    // Split input with the pattern
                    String[] result = pattern.split(value);
                    for (int i=0; i<result.length; i++) {
                        if (value.contains("${"+result[i]+"}")) {
                                String 
v=mvnproperties.getProperty(result[i]);
                                if (v != null ) {

value=value.replace("${"+result[i]+"}",v);
                                } else {
                                    //WE REALLY NEED TO DO THIS because 
flex compiler doesn't like
                                    //${} constructions in defines. so 
if we don't have a value we just
                                    //put in null. This will probebly 
only work for string defines 
                                    //where we say "${xxx}" as value
                                    //
                                    //Note: this will also do the 
same "thing" as with the old Map implementation 
                                    //where Maven inserts "null" when 
property was not defined

value=value.replace("${"+result[i]+"}","null");
                                }
                        }
                    }
                }
                getLog().info( "define " + key + " = " + value );
                configuration.addDefineDirective(key, value );
            }
        }
    }

Note that if propertie doesn't exist , the ${xxx} will be replaced by the 
text "null"
this is really needed because :
- the "old" implementation also did this (maven did it ;-)
- Flex compiler doesn't like ${...}, even not for strings 

I don't know if this is OK for you. we need some additional test/uses cases
to confirm it works for most people.

luc

attached you find my java source file for testing

Original comment by luc.w...@gmail.com on 22 Oct 2008 at 1:58

Attachments:

GoogleCodeExporter commented 9 years ago
Take a look at TRUNK.  The code looks less ugly there =p

Fixed at revision 834

Original comment by velo...@gmail.com on 22 Oct 2008 at 2:44

GoogleCodeExporter commented 9 years ago
additional thought about this mater:
<XXX::YYY>zzz</XXX::YYY> constructions are not valid.

but <xxx..yyy>zzz</xxx..yyy> are valid (atleast xmllint doesn't complain about 
it).

in the flex-compiler code we could easally replace .. with ::
so the final name would be xxx::yyy

ok , this is hacking but atleast it doesn't need the ugly ${xxx} replace hack.

Original comment by luc.w...@gmail.com on 22 Oct 2008 at 2:45

GoogleCodeExporter commented 9 years ago
internet goes fast ;-) but the trunk seems to be a little bit different ?

Some  first impression remarks after looking at the code:
My original code was basicly the same BUT it didn't not work with
properties that are "injected" by other modules during execution. this is
happening with the codehouse Build Number plugin i'm using. 

what I mean is that ${project.version} will work because this is "staticly"
inserted by maven. but ${buildNumber} stays ${buildNumber} and is not
replaced by the actual value because this is created by the build number plugin 
, 
just before compile goal ,into the maven environment.

so that's why i have this little hack.

Now , the OLD code this would work. so ${buildNumber} was actually replaced by
its value or "null" incase no ${buildNumber} was defined.
the hack mimics this behaveour.

the "null" stuff is important because the flex compiler complains when
he sees something like -defines +VERSION::revision,"${buildNumber}"

Original comment by luc.w...@gmail.com on 22 Oct 2008 at 3:02

GoogleCodeExporter commented 9 years ago
Great news,

it's a bug at the plexus Properties converter. It doesn't attempt to interpolate
names/values.

I will see what can I do about that. For now, keep with your code.

BTW, which maven version are you using?

VELO

Original comment by velo...@gmail.com on 22 Oct 2008 at 3:25

GoogleCodeExporter commented 9 years ago
maven 2.0.9

luc

Original comment by luc.w...@gmail.com on 22 Oct 2008 at 4:02

GoogleCodeExporter commented 9 years ago
hello Velo,

I did some testing with both <defines> and <definesDeclaration>
in 1 pom to see the difference in handle.

my plugin configuration :
... 
<plugin>
   <groupId>info.flex-mojos</groupId>
   <artifactId>flex-compiler-mojo</artifactId>
   <extensions>true</extensions>
   <version>2.0M8-SNAPSHOT</version>
   <configuration>
     <definesDeclaration>                                 
      <property>
        <name>VERSION::revision</name><value>"${buildNumber}"</value>
      </property>
     </definesDeclaration>
     <defines>
       <VERSION::test>"${buildNumber}"</VERSION::test>
     </defines>
   </configuration>
  </plugin>

both defines should give the same value , but running mvn install gives :
[INFO] [buildnumber:create {execution: default}]
[INFO] Checking for local modifications: skipped.
[INFO] Executing: svn --non-interactive update
[INFO] Working directory: /home/luc/src/luma/lw2pcmodel
[INFO] No files needed updating.
[INFO] Storing buildNumber: 302 at timestamp: 1224694196993
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
created
[WARNING] DEPRECATED [defines]: See definesDeclaration
[INFO] [flex-compiler-mojo:compile-swc]
[INFO] Using configuration 
file /home/luc/src/luma/lw2pcmodel/target/flex-compiler/config.xml
[WARNING] Nothing expecified to include.  Assuming source folders.
[INFO] Flex compiler configurations:
-compiler.accessible=false
-compiler.actionscript-file-encoding UTF-8
-compiler.allow-source-path-overlap=false
-compiler.as3=true
-compiler.debug=false
-compiler.define+=VERSION::test,"302"
-compiler.define+=VERSION::revision,"${buildNumber}"
-compiler.es=false
-compiler.external-library-path 
/home/luc/src/luma/lw2pcmodel/target/flex-compiler/libraries/playerglobal.swc
-compiler.fonts.local-fonts-snapshot 
/home/luc/src/luma/lw2pcmodel/target/flex-compiler/fonts.ser
-compiler.headless-server=true
-compiler.include-libraries=
-compiler.keep-all-type-selectors=false
-compiler.keep-generated-actionscript=false
-compiler.library-path 
/home/luc/.m2/repository/com/adobe/flex/framework/framework/3.0.0.477/framework-
3.0.0.477.swc 
/home/luc/.m2/repository/com/adobe/flex/framework/utilities/3.0.0.477/utilities-
3.0.0.477.swc 
/home/luc/.m2/repository/com/adobe/flex/framework/flex/3.0.0.477/flex-3.0.0.477.
swc 
/home/luc/.m2/repository/com/adobe/flex/framework/rpc/3.0.0.477/rpc-3.0.0.477.sw
c 
/home/luc/.m2/repository/com/adobe/flex/framework/rpc/3.0.0.477/rpc-3.0.0.477-en
_US.rb.swc 
/home/luc/.m2/repository/com/adobe/flex/framework/framework/3.0.0.477/framework-
3.0.0.477-en_US.rb.swc
-compiler.locale en_US
-compiler.optimize=true
-compiler.source-path /home/luc/src/luma/lw2pcmodel/src/main/flex
-compiler.strict=true
-compiler.theme=
-compiler.use-resource-bundle-metadata=true
-compiler.verbose-stacktraces=false
-compute-digest=true
-default-background-color 8821927
-default-frame-rate 24
-default-script-limits 1000 60
-default-size 500 375
-load-config /home/luc/src/luma/lw2pcmodel/target/flex-compiler/config.xml
-metadata.date Wed Oct 22 18:50:00 CEST 2008
-metadata.language en_US
-metadata.localized-description en_US luma project pom
-metadata.localized-title en_US lw2pcmodel
-target-player 9.0.0
-use-network=true
-verify-digests=true
[INFO] Loading configuration 
file /home/luc/src/luma/lw2pcmodel/target/flex-compiler/config.xml
[ERROR] command line:[-1,-1] configuration variable 'compiler.define' value 
contains 
unknown token 'buildNumber'
Use 'oem -help' for information about using the command line.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error compiling!

as you can see in de begin of the log, buildNumber is set to 302 by de 
buildNumber 
mojo. 

the VERSION::test using the "old" defines is ok , but the new defineDeclaration 
doesn't work the same.

Original comment by luc.w...@gmail.com on 22 Oct 2008 at 4:51

GoogleCodeExporter commented 9 years ago
Yep, the problem is here:
http://svn.codehaus.org/plexus/plexus-containers/trunk/plexus-container-default/
src/main/java/org/codehaus/plexus/component/configurator/converters/composite/Pr
opertiesConverter.java

It is not attempting to interpolate.

Original comment by velo...@gmail.com on 22 Oct 2008 at 4:55

GoogleCodeExporter commented 9 years ago
hello velo ,

I search a bit in the maven source "jungle" and found a way to use the 
Maven PluginParameterExpressionEvaluator at runtime. 
this ExpressionEvaluator does the hard work of replacing all ${xxx} stuff

based on your comment #10 , i would expect that this is a maven-core issue and 
will not be fix until 2.0.xx

So i would suggest to review this new implementation and include it as 
workaround for
the maven issue in 2.0M8 release

Some implementation notes: 
- it needs atleast version 2.0.8 from maven because of MNG-3062,so you need to
  increase maven.version in your parent pom.
- maybe add a configuration to disable this if not wanted. it can be off by 
default
- then new context & execution parameter add to AbstractFlexCompilerMojo can go 
  to AbstractIrvinMojo if you like to have it there.
- it add a dependency to maven-core plugin so you need to add this to your 
pom.xml
- attach you find a update AbstractFlexCompilerMojo based on revision 836

Original comment by luc.w...@gmail.com on 23 Oct 2008 at 7:56

Attachments:

GoogleCodeExporter commented 9 years ago
I add your interpolation to TRUNK.

BTW, great work on this patch.

Original comment by velo...@gmail.com on 27 Oct 2008 at 7:05

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Does flexmojos 3.8 maven plugin have this fix/patch in it?

Original comment by pulkitsi...@gmail.com on 28 Dec 2010 at 7:41