Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBDS-3187 more refactoring and tweaks >> master #235

Merged
merged 5 commits into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<name>JBDS - Product, Installers</name>
<packaging>pom</packaging>
<modules>
<module>rules</module>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be in separate module?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey. Now I see its to make a custom rule.

A) that really should be somewhere outside this repo Imo.
B) could this not be done wit standard banned dependencies enforcer rule?
C) if not, just use banshee avoiding all these boiler plate code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A) Your constructive feedback is appreciated. Please elaborate on why a check done when building the devstudio-product should be housed outside the devstudio-product repo. By co-locating it, the check will fail for LOCAL builds as well as those in Jenkins. By locating it elsewhere, it won't. Rather than voicing a difference of opinion, please explain why your approach is better.

B) Perhaps, but we can also expand this single usecase to include MORE tests/validations. Don't you want to verify MORE than just one thing? Surely we can make the build BETTER with more rules and checks? This is just an initial attempt to prove it can be done, and implement it, too. Once we have a template for how to write rules, we can then write more.

C) What is Banshee and how would it apply here? Could you provide a link, sample code, etc? I tried googling for "maven banshee" and didn't find anything useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A) IMO you are writing a maven enforcer rule that is not devstudio specific, but sounds like you want these rules to be custom of devstudio. I prefer a few lines of xml rather than alot of boilerplate code.
B) I dont understand why we need to add custom code like this when there seem to perfectly fine standard enforcer rules for this. The day we actually have custom rules that needs custom code then i'm all for doing that.
C) damn autocorrect. was meant to write beanshell - but that was before I fully grokked that you don't actually need any custom logic here. So that point is mute since we can just remove it all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A) btw. I do not understand why you think moving the rule implementation out to a separate repo (i.e. where our other maven rules are defined) would not make the rule fail both locally and in hudson.). This pom will still have the actual rule defined, so it will still fail.

<module>plugins</module>
<module>features</module>
<module>site</module>
Expand Down Expand Up @@ -45,6 +46,34 @@
<buildEAPBundle>false</buildEAPBundle>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<dependencies>
<dependency>
<groupId>com.jboss.devstudio</groupId>
<artifactId>ParentPomVersionCheckRule</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>enforce</id>
<configuration><rules>
<ParentPomVersionCheckRule implementation="com.jboss.devstudio.enforcer.rule.ParentPomVersionCheckRule"><shouldIfail>true</shouldIfail></ParentPomVersionCheckRule>
</rules></configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<!--
Addendum to "hudson" profile from parent pom. This adds the correct download URL for EAP 6.3.0, which is not a public URL (unlike 6.1.0.Alpha).
Expand Down
73 changes: 73 additions & 0 deletions rules/com.jboss.devstudio.enforcer.rule/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
-->
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jboss.devstudio</groupId>
<artifactId>ParentPomVersionCheckRule</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>ParentPomVersionCheckRule</name>
<description>Checks if JBT upstream parent pom is Final and fails if no -DBUILD_ALIAS=GA override provided.</description>
<properties>
<api.version>1.0-beta-1</api.version>
<maven.version>2.0.9</maven.version>
</properties>
<build>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer-api</artifactId>
<version>${api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<version>1.0-alpha-9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.jboss.devstudio.enforcer.rule;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.enforcer.rule.api.EnforcerRule;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;

/**
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
*/
public class ParentPomVersionCheckRule
implements EnforcerRule
{
/**
* Simple param. This rule will fail if the value is true.
*/
private boolean shouldIfail = false;

public void execute( EnforcerRuleHelper helper )
throws EnforcerRuleException
{
Log log = helper.getLog();

try
{
// get the various expressions out of the helper.
MavenProject project = (MavenProject) helper.evaluate( "${project}" );
MavenSession session = (MavenSession) helper.evaluate( "${session}" );
String target = (String) helper.evaluate( "${project.build.directory}" );
String artifactId = (String) helper.evaluate( "${project.artifactId}" );

// retreive any component out of the session directly
ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class );
RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class );

log.info( "Retrieved Target Folder: " + target );
log.info( "Retrieved ArtifactId: " +artifactId );
log.info( "Retrieved Project: " + project );
log.info( "Retrieved RuntimeInfo: " + rti );
log.info( "Retrieved Session: " + session );
log.info( "Retrieved Resolver: " + resolver );

// retrieve the version of the parent pom; if it contains .Final then JBDS builds need to override with -DBUILD_ALIAS=GA
String parentVersion = (String) helper.evaluate( "${project.parent.version}" );
String BUILD_ALIAS = (String) helper.evaluate( "${BUILD_ALIAS}" );

if ( this.shouldIfail && parentVersion.indexOf(".Final")>0 && !BUILD_ALIAS.equals("GA"))
{
throw new EnforcerRuleException( " ** Parent pom version ("+parentVersion+") contains .Final; must set -DBUILD_ALIAS=GA **");
}
}
catch ( ComponentLookupException e )
{
throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e );
}
catch ( ExpressionEvaluationException e )
{
throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e );
}
}

/**
* If your rule is cacheable, you must return a unique id when parameters or conditions
* change that would cause the result to be different. Multiple cached results are stored
* based on their id.
*
* The easiest way to do this is to return a hash computed from the values of your parameters.
*
* If your rule is not cacheable, then the result here is not important, you may return anything.
*/
public String getCacheId()
{
//no hash on boolean...only parameter so no hash is needed.
return ""+this.shouldIfail;
}

/**
* This tells the system if the results are cacheable at all. Keep in mind that during
* forked builds and other things, a given rule may be executed more than once for the same
* project. This means that even things that change from project to project may still
* be cacheable in certain instances.
*/
public boolean isCacheable()
{
return false;
}

/**
* If the rule is cacheable and the same id is found in the cache, the stored results
* are passed to this method to allow double checking of the results. Most of the time
* this can be done by generating unique ids, but sometimes the results of objects returned
* by the helper need to be queried. You may for example, store certain objects in your rule
* and then query them later.
*/
public boolean isResultValid( EnforcerRule arg0 )
{
return false;
}
}
152 changes: 152 additions & 0 deletions rules/com.jboss.devstudio.enforcer.rule/usage-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
-->
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jboss.devstudio</groupId>
<artifactId>ParentPomVersionCheck</artifactId>
<version>0.1</version>
<packaging>jar</packaging>

<parent>
<groupId>org.jboss.tools</groupId>
<artifactId>parent</artifactId>
<version>4.2.0.Final-SNAPSHOT</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<dependencies>
<dependency>
<groupId>com.jboss.devstudio</groupId>
<artifactId>ParentPomVersionCheckRule</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>enforce</id>
<configuration><rules>
<ParentPomVersionCheckRule implementation="com.jboss.devstudio.enforcer.rule.ParentPomVersionCheckRule"><shouldIfail>true</shouldIfail></ParentPomVersionCheckRule>
</rules></configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<!--
Addendum to "hudson" profile from parent pom. This adds the correct download URL for EAP 6.3.0, which is not a public URL (unlike 6.1.0.Alpha).
-->
<profile>
<id>hudson</id>
<properties>
<eapVersion>6.3.0</eapVersion>
<eapURL>http://download.devel.redhat.com/released/JBEAP-6/6.3.0/jboss-eap-6.3.0.zip</eapURL>
<eapMD5>f1ce6b83cd117bc612e9d15ff64575dd</eapMD5>
<eapRootFolder>jboss-eap-6.3</eapRootFolder>
</properties>
</profile>

<!--
Uncomment this profile to optionally enable a target platform site instead of (or in addition to) the default target platform.
Use -Dno-target-platform if you want to disable the default target platform in favour of a specified target platform site
mvn clean install -Dno-target-platform \
-Djbosstools-target-site=file:///path/to/jbosstools-target-platforms/jbdevstudio/multiple/target/jbdevstudio-multiple.target.repo/
-->
<!-- <profile>
<id>target-site</id>
<activation>
<property>
<name>jbosstools-target-site</name>
</property>
</activation>
<repositories>
<repository>
<id>jbosstools-target-site</id>
<layout>p2</layout>
<url>${jbosstools-target-site}</url>
</repository>
</repositories>
</profile> -->
</profiles>

<repositories>
<repository>
<id>jboss-releases</id>
<name>JBoss Releases Maven Repository</name>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why repeating these settings here? they should be in users settingsxml already anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn't be there. In fact, that file needn't be there. I've deleted it.

<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>jboss-snapshots-repository</id>
<name>JBoss Snapshots Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- since JBT site is no longer set in parent pom, must explicitly define it here -->
<repository>
<id>jbosstools-site</id>
<layout>p2</layout>
<url>${jbosstools-site}</url>
</repository>
</repositories>

<!-- Additional m2 repos to resolve things like org.eclipse.tycho:tycho-maven-plugin:0.16.0-SNAPSHOT -->
<!-- JBoss Nexus repos are also added, but in settings.xml -->
<pluginRepositories>
<pluginRepository>
<id>sonatype-public-grid</id>
<url>https://repository.sonatype.org/content/groups/sonatype-public-grid</url>
</pluginRepository>
<pluginRepository>
<id>sonatype-public-repository</id>
<url>https://oss.sonatype.org/content/groups/public</url>
</pluginRepository>
<pluginRepository>
<id>jboss-releases</id>
<name>JBoss Releases Maven Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>jboss-snapshots-repository</id>
<name>JBoss Snapshots Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>