Spring Roo
  1. Spring Roo
  2. ROO-2946

Use interface instead of concrete classes for DependencyType and DependencyScope

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.0.RC1
    • Fix Version/s: None
    • Component/s: @ CORE
    • Labels:
      None
    • Environment:
      All versions are affected

      Description

      I'm developing an addon for flex.

      The artifact types for flex includes "SWF", "SWC", etc...
      The artifact scopes have been extended in flexMojos to include "CACHING", "RSL", "THEME", etc...

      Actualy, the actual Enum classes that are respectively DependencyType and DependencyScope don't implement any interface, it's then not possible for me to create dynamically dependencies using other types or scopes, the only way I can inject these kinds of artifacts is thru a template and then rewrite the value in the pom.xml (which is not taken in account by the Maven Metadatas, in more, it can be very tedious especially because I want the addon to be able to manage several user versions of the flexSQK and the pom dependencies can completly change relativly to the version which means with the current rigid implementation of those Enum, I've to implement a lot of tricky forks to reach the goal.

      In more, I've seen that in the trunk, you added a public static functions in those Enum classes, it doesn't go through the flexibility.

      Then, I suggest to use interfaces instead of concrete classes as much as you can to allow a needed better flexibility.

      Thank you for your understanding.

        Activity

        Show
        Frédéric THOMAS added a comment - https://jira.springsource.org/browse/ROO-2946
        Hide
        Alan Stewart added a comment -

        Please post an example from your pom which shows these dependencies

        Show
        Alan Stewart added a comment - Please post an example from your pom which shows these dependencies
        Hide
        Frédéric THOMAS added a comment -

        Notice the types and scopes in the dependencies of this POM.

        Bar.java
        <?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        
        	<modelVersion>4.0.0</modelVersion>
        	<parent>
        		<groupId>com.adobe.cairngorm.todo</groupId>
        		<artifactId>todo</artifactId>
        		<version>1.0-SNAPSHOT</version>
        		<relativePath>../pom.xml</relativePath>
        	</parent>
        	<artifactId>todo_flex</artifactId>
        	<name>${project.groupId} ${project.artifactId} ${project.version}</name>
        	<description>This project hold the flex application parent build
        	</description>
        	<packaging>pom</packaging>
        
        
        
        	<modules>
        		<module>todo_flex_remoting_dto</module>
        		<module>todo_flex_core</module>
        		<module>todo_flex_todolist_lib</module>
        		<module>todo_flex_todolist</module>
        		<module>todo_flex_shell</module>
        	</modules>
        
        	<properties>
        		<flexpmd.version>1.0</flexpmd.version>
        		<flex-pmd-cpd.max.token>50</flex-pmd-cpd.max.token>
        
        		<header.path>../../../src/conf/header.txt</header.path>
        	</properties>
        
        
        	<profiles>
        		<profile>
        			<id>dev</id>
        			<activation>
        				<activeByDefault>true</activeByDefault>
        			</activation>
        			<properties>
        				<flex-debug>true</flex-debug>
        				<flex-optimize>false</flex-optimize>
        				<flex-verbose-stacktraces>true</flex-verbose-stacktraces>
        			</properties>
        		</profile>
        		<profile>
        			<id>production</id>
        			<properties>
        				<flex-debug>false</flex-debug>
        				<flex-optimize>true</flex-optimize>
        				<flex-verbose-stacktraces>false</flex-verbose-stacktraces>
        			</properties>
        		</profile>
        	</profiles>
        
        	<dependencies>
        
        		<!-- Dynamically load the Adobe signed RSL framework instead of merging 
        			into SWF. -->
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>textLayout</artifactId>
        			<type>swc</type>
        			<scope>caching</scope>
        		</dependency>
        		<!-- OSMF SWC would go here. -->
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>framework</artifactId>
        			<type>swc</type>
        			<scope>caching</scope>
        		</dependency>
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>spark</artifactId>
        			<type>swc</type>
        			<scope>caching</scope>
        		</dependency>
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>sparkskins</artifactId>
        			<type>swc</type>
        			<scope>caching</scope>
        		</dependency>
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>rpc</artifactId>
        			<type>swc</type>
        			<scope>caching</scope>
        		</dependency>
        		<!-- Flex framework resource bundles -->
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>flex-framework</artifactId>
        			<type>pom</type>
        		</dependency>
        		<!-- eof common flex4 sdk dependencies -->
        
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>playerglobal</artifactId>
        			<type>swc</type>
        			<classifier>${player.version}</classifier>
        		</dependency>
        		<dependency>
        			<groupId>com.adobe.flex.framework</groupId>
        			<artifactId>playerglobal</artifactId>
        			<type>rb.swc</type>
        		</dependency>
        		<!-- eof flex-4 sdk dependencies -->
        
        		<dependency>
        			<groupId>org.spicefactory</groupId>
        			<artifactId>parsley-flex4</artifactId>
        			<type>swc</type>
        		</dependency>
        
        		<dependency>
        			<groupId>org.spicefactory</groupId>
        			<artifactId>spicelib-flex</artifactId>
        			<type>swc</type>
        		</dependency>
        
        		<dependency>
        			<groupId>com.adobe.flexunit</groupId>
        			<artifactId>flexunit</artifactId>
        			<type>swc</type>
        		</dependency>
        
        		<dependency>
        			<groupId>com.adobe.flexunit</groupId>
        			<artifactId>flexunit</artifactId>
        			<type>swc</type>
        			<scope>test</scope>
        		</dependency>
        
        	</dependencies>
        
        
        	<dependencyManagement>
        		<dependencies>
        			<!-- Dynamically load the Adobe signed RSL framework instead of merging 
        				into SWF. -->
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>textLayout</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>swc</type>
        				<scope>caching</scope>
        			</dependency>
        			<!-- OSMF SWC would go here. -->
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>framework</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>swc</type>
        				<scope>caching</scope>
        			</dependency>
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>spark</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>swc</type>
        				<scope>caching</scope>
        			</dependency>
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>sparkskins</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>swc</type>
        				<scope>caching</scope>
        			</dependency>
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>rpc</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>swc</type>
        				<scope>caching</scope>
        			</dependency>
        			<!-- Flex framework resource bundles -->
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>flex-framework</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>pom</type>
        			</dependency>
        
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>playerglobal</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>swc</type>
        				<classifier>${player.version}</classifier>
        			</dependency>
        			<dependency>
        				<groupId>com.adobe.flex.framework</groupId>
        				<artifactId>playerglobal</artifactId>
        				<version>${flex.sdk.version}</version>
        				<type>rb.swc</type>
        			</dependency>
        			<!-- eof flex-4 sdk dependencies -->
        
        			<dependency>
        				<groupId>com.adobe.cairngorm</groupId>
        				<artifactId>integration</artifactId>
        				<version>0.18-SNAPSHOT</version>
        				<type>swc</type>
        			</dependency>
        
        			<dependency>
        				<groupId>com.adobe.cairngorm</groupId>
        				<artifactId>integrationParsley</artifactId>
        				<version>0.18-SNAPSHOT</version>
        				<type>swc</type>
        			</dependency>
        
        			<dependency>
        				<groupId>com.adobe.cairngorm</groupId>
        				<version>0.18-SNAPSHOT</version>
        				<artifactId>module</artifactId>
        				<type>swc</type>
        			</dependency>
        
        			<dependency>
        				<groupId>org.spicefactory</groupId>
        				<artifactId>parsley-flex4</artifactId>
        				<version>${parsley.version}</version>
        				<type>swc</type>
        			</dependency>
        
        			<dependency>
        				<groupId>org.spicefactory</groupId>
        				<artifactId>spicelib-flex</artifactId>
        				<version>${spicelib.version}</version>
        				<type>swc</type>
        			</dependency>
        
        			<dependency>
        				<groupId>com.adobe.flexunit</groupId>
        				<artifactId>flexunit</artifactId>
        				<version>${flexunit.version}</version>
        				<type>swc</type>
        			</dependency>
        
        			<dependency>
        				<groupId>com.adobe.flexunit</groupId>
        				<artifactId>flexunit</artifactId>
        				<version>${flexunit.version}</version>
        				<type>swc</type>
        				<scope>test</scope>
        			</dependency>
        
        		</dependencies>
        	</dependencyManagement>
        
        	<reporting>
        		<plugins>
        			<plugin>
        				<groupId>org.apache.maven.plugins</groupId>
        				<artifactId>maven-project-info-reports-plugin</artifactId>
        				<version>2.1.1</version>
        				<configuration>
        					<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
        					<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
        				</configuration>
        			</plugin>
        			<plugin>
        				<groupId>org.apache.maven.plugins</groupId>
        				<artifactId>maven-surefire-report-plugin</artifactId>
        				<version>2.4.3</version>
        				<configuration>
        					<reportsDirectory>surefire-reports</reportsDirectory>
        				</configuration>
        			</plugin>
        			<plugin>
        				<groupId>com.adobe.ac</groupId>
        				<artifactId>flex-pmd-metrics-maven-plugin</artifactId>
        				<version>${flexpmd.version}</version>
        			</plugin>
        			<plugin>
        				<groupId>com.adobe.ac</groupId>
        				<artifactId>flex-pmd-maven-plugin</artifactId>
        				<version>${flexpmd.version}</version>
        				<configuration>
        					<ruleSet>${basedir}/../src/conf/radon-flex-pmd-ruleset.xml</ruleSet>
        				</configuration>
        			</plugin>
        			<plugin>
        				<groupId>com.adobe.ac</groupId>
        				<artifactId>flex-pmd-cpd-maven-plugin</artifactId>
        				<version>${flexpmd.version}</version>
        				<configuration>
        					<minimumTokenCount>${flex-pmd-cpd.max.token}</minimumTokenCount>
        				</configuration>
        			</plugin>
        
        
        		</plugins>
        	</reporting>
        
        
        
        </project>
        
        Show
        Frédéric THOMAS added a comment - Notice the types and scopes in the dependencies of this POM. Bar.java <?xml version= "1.0" encoding= "UTF-8" ?> <project xmlns= "http: //maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http: //maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.adobe.cairngorm.todo</groupId> <artifactId>todo</artifactId> <version>1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <artifactId>todo_flex</artifactId> <name>${project.groupId} ${project.artifactId} ${project.version}</name> <description>This project hold the flex application parent build </description> <packaging>pom</packaging> <modules> <module>todo_flex_remoting_dto</module> <module>todo_flex_core</module> <module>todo_flex_todolist_lib</module> <module>todo_flex_todolist</module> <module>todo_flex_shell</module> </modules> <properties> <flexpmd.version>1.0</flexpmd.version> <flex-pmd-cpd.max.token>50</flex-pmd-cpd.max.token> <header.path>../../../src/conf/header.txt</header.path> </properties> <profiles> <profile> <id>dev</id> <activation> <activeByDefault> true </activeByDefault> </activation> <properties> <flex-debug> true </flex-debug> <flex-optimize> false </flex-optimize> <flex-verbose-stacktraces> true </flex-verbose-stacktraces> </properties> </profile> <profile> <id>production</id> <properties> <flex-debug> false </flex-debug> <flex-optimize> true </flex-optimize> <flex-verbose-stacktraces> false </flex-verbose-stacktraces> </properties> </profile> </profiles> <dependencies> <!-- Dynamically load the Adobe signed RSL framework instead of merging into SWF. --> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>textLayout</artifactId> <type>swc</type> <scope>caching</scope> </dependency> <!-- OSMF SWC would go here. --> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>framework</artifactId> <type>swc</type> <scope>caching</scope> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>spark</artifactId> <type>swc</type> <scope>caching</scope> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>sparkskins</artifactId> <type>swc</type> <scope>caching</scope> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>rpc</artifactId> <type>swc</type> <scope>caching</scope> </dependency> <!-- Flex framework resource bundles --> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>flex-framework</artifactId> <type>pom</type> </dependency> <!-- eof common flex4 sdk dependencies --> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>playerglobal</artifactId> <type>swc</type> <classifier>${player.version}</classifier> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>playerglobal</artifactId> <type>rb.swc</type> </dependency> <!-- eof flex-4 sdk dependencies --> <dependency> <groupId>org.spicefactory</groupId> <artifactId>parsley-flex4</artifactId> <type>swc</type> </dependency> <dependency> <groupId>org.spicefactory</groupId> <artifactId>spicelib-flex</artifactId> <type>swc</type> </dependency> <dependency> <groupId>com.adobe.flexunit</groupId> <artifactId>flexunit</artifactId> <type>swc</type> </dependency> <dependency> <groupId>com.adobe.flexunit</groupId> <artifactId>flexunit</artifactId> <type>swc</type> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <!-- Dynamically load the Adobe signed RSL framework instead of merging into SWF. --> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>textLayout</artifactId> <version>${flex.sdk.version}</version> <type>swc</type> <scope>caching</scope> </dependency> <!-- OSMF SWC would go here. --> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>framework</artifactId> <version>${flex.sdk.version}</version> <type>swc</type> <scope>caching</scope> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>spark</artifactId> <version>${flex.sdk.version}</version> <type>swc</type> <scope>caching</scope> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>sparkskins</artifactId> <version>${flex.sdk.version}</version> <type>swc</type> <scope>caching</scope> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>rpc</artifactId> <version>${flex.sdk.version}</version> <type>swc</type> <scope>caching</scope> </dependency> <!-- Flex framework resource bundles --> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>flex-framework</artifactId> <version>${flex.sdk.version}</version> <type>pom</type> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>playerglobal</artifactId> <version>${flex.sdk.version}</version> <type>swc</type> <classifier>${player.version}</classifier> </dependency> <dependency> <groupId>com.adobe.flex.framework</groupId> <artifactId>playerglobal</artifactId> <version>${flex.sdk.version}</version> <type>rb.swc</type> </dependency> <!-- eof flex-4 sdk dependencies --> <dependency> <groupId>com.adobe.cairngorm</groupId> <artifactId>integration</artifactId> <version>0.18-SNAPSHOT</version> <type>swc</type> </dependency> <dependency> <groupId>com.adobe.cairngorm</groupId> <artifactId>integrationParsley</artifactId> <version>0.18-SNAPSHOT</version> <type>swc</type> </dependency> <dependency> <groupId>com.adobe.cairngorm</groupId> <version>0.18-SNAPSHOT</version> <artifactId>module</artifactId> <type>swc</type> </dependency> <dependency> <groupId>org.spicefactory</groupId> <artifactId>parsley-flex4</artifactId> <version>${parsley.version}</version> <type>swc</type> </dependency> <dependency> <groupId>org.spicefactory</groupId> <artifactId>spicelib-flex</artifactId> <version>${spicelib.version}</version> <type>swc</type> </dependency> <dependency> <groupId>com.adobe.flexunit</groupId> <artifactId>flexunit</artifactId> <version>${flexunit.version}</version> <type>swc</type> </dependency> <dependency> <groupId>com.adobe.flexunit</groupId> <artifactId>flexunit</artifactId> <version>${flexunit.version}</version> <type>swc</type> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.1.1</version> <configuration> <dependencyLocationsEnabled> false </dependencyLocationsEnabled> <dependencyDetailsEnabled> false </dependencyDetailsEnabled> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.4.3</version> <configuration> <reportsDirectory>surefire-reports</reportsDirectory> </configuration> </plugin> <plugin> <groupId>com.adobe.ac</groupId> <artifactId>flex-pmd-metrics-maven-plugin</artifactId> <version>${flexpmd.version}</version> </plugin> <plugin> <groupId>com.adobe.ac</groupId> <artifactId>flex-pmd-maven-plugin</artifactId> <version>${flexpmd.version}</version> <configuration> <ruleSet>${basedir}/../src/conf/radon-flex-pmd-ruleset.xml</ruleSet> </configuration> </plugin> <plugin> <groupId>com.adobe.ac</groupId> <artifactId>flex-pmd-cpd-maven-plugin</artifactId> <version>${flexpmd.version}</version> <configuration> <minimumTokenCount>${flex-pmd-cpd.max.token}</minimumTokenCount> </configuration> </plugin> </plugins> </reporting> </project>
        Hide
        Frédéric THOMAS added a comment -

        A very quick solution can be :

        DependencyType.java
        
        package org.springframework.roo.project;
        
        /**
         * The type of dependency.
         * 
         * @author Ben Alex
         * @since 1.0
         *
         */
        public enum DependencyType {
        	JAR,
        	ZIP,
        	POM,
        	SWC,
        	SWF,
        	OTHER
        }
        
        DependencyScope.java
        
        package org.springframework.roo.project;
        
        /**
         * The scope of the dependency.
         * 
         * @author Alan Stewart
         * @since 1.1
         */
        public enum DependencyScope {
        	COMPILE,
        	PROVIDED,
        	RUNTIME,
        	TEST,
        	SYSTEM,
        	IMPORT,
        	CACHING,
        	RSL,
        	THEME;
        }
        
        Dependency.java
        package org.springframework.roo.project;
        ...
        
        	/**
        	 * Convenience constructor when an XML element is available that represents a Maven <dependency>.
        	 * 
        	 * @param dependency to parse (required)
        	 */
        	public Dependency(Element dependency) {
                ...
        
        			// POM attributes supported in Maven 3.1
        			if (XmlUtils.findFirstElement("type", dependency) != null || dependency.hasAttribute("type")) {
        				String t;
        				if (dependency.hasAttribute("type")) {
        					t = dependency.getAttribute("type");
        				} else {
        					t = XmlUtils.findFirstElement("type", dependency).getTextContent().trim().toUpperCase();
        				}				
        				try {
        					type = DependencyType.valueOf(t);
        				} catch (IllegalArgumentException e) {
        					type = DependencyType.OTHER;
        				}
        			}
        
        			// POM attributes supported in Maven 3.1
        			scope = DependencyScope.COMPILE;
        			if (XmlUtils.findFirstElement("scope", dependency) != null || dependency.hasAttribute("scope")) {
        				String s;
        				if (dependency.hasAttribute("scope")) {
        					s = dependency.getAttribute("scope");
        				} else {
        					s = XmlUtils.findFirstElement("scope", dependency).getTextContent().trim().toUpperCase();
        				}
        				try {
        					scope = DependencyScope.valueOf(s);
        				} catch (IllegalArgumentException e) {
        					throw new IllegalArgumentException("Invalid dependency scope: " + s);
        				}
        			}
                                ...
        		}
                        ...
        }
        
        Show
        Frédéric THOMAS added a comment - A very quick solution can be : DependencyType.java package org.springframework.roo.project; /** * The type of dependency. * * @author Ben Alex * @since 1.0 * */ public enum DependencyType { JAR, ZIP, POM, SWC, SWF, OTHER } DependencyScope.java package org.springframework.roo.project; /** * The scope of the dependency. * * @author Alan Stewart * @since 1.1 */ public enum DependencyScope { COMPILE, PROVIDED, RUNTIME, TEST, SYSTEM, IMPORT, CACHING, RSL, THEME; } Dependency.java package org.springframework.roo.project; ... /** * Convenience constructor when an XML element is available that represents a Maven <dependency>. * * @param dependency to parse (required) */ public Dependency(Element dependency) { ... // POM attributes supported in Maven 3.1 if (XmlUtils.findFirstElement( "type" , dependency) != null || dependency.hasAttribute( "type" )) { String t; if (dependency.hasAttribute( "type" )) { t = dependency.getAttribute( "type" ); } else { t = XmlUtils.findFirstElement( "type" , dependency).getTextContent().trim().toUpperCase(); } try { type = DependencyType.valueOf(t); } catch (IllegalArgumentException e) { type = DependencyType.OTHER; } } // POM attributes supported in Maven 3.1 scope = DependencyScope.COMPILE; if (XmlUtils.findFirstElement( "scope" , dependency) != null || dependency.hasAttribute( "scope" )) { String s; if (dependency.hasAttribute( "scope" )) { s = dependency.getAttribute( "scope" ); } else { s = XmlUtils.findFirstElement( "scope" , dependency).getTextContent().trim().toUpperCase(); } try { scope = DependencyScope.valueOf(s); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Invalid dependency scope: " + s); } } ... } ... }

          People

          • Assignee:
            Unassigned
            Reporter:
            Frédéric THOMAS
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: