Skip to content

Commit

Permalink
Integration test fixed
Browse files Browse the repository at this point in the history
Checkstyle fixed
  • Loading branch information
alevohin committed Jan 3, 2015
1 parent c59fe77 commit 884bd4f
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 34 deletions.
8 changes: 5 additions & 3 deletions qulice-ant/src/it/findbugs-violations/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
classpath="${com.qulice:qulice-ant:jar}"/>

<target name="qulice" description="Execute qulice checks">
<property name="license" value="${basedir}\LICENSE.txt"/>
<property name="license" value="LICENSE.txt"/>

<qulice
sourcepath="${basedir}/src/main/java"
classpath="${basedir}/target/classes"/>
srcdir="${basedir}/src/main/java"
classesdir="${basedir}/target/classes"
classpath="${basedir}/target/classes:${basedir}"/>
</target>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
/**
* This project has a license.
* Copyright (c) 2011-2014, Qulice.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the Qulice.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.qulice.foo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
/**
* This project has a license.
* Copyright (c) 2011-2014, Qulice.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the Qulice.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.qulice.foo;
3 changes: 3 additions & 0 deletions qulice-ant/src/it/findbugs-violations/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@
*/

def log = new File(basedir, 'build.log')
assert log.text.contains('No Checkstyle violations found in 2 files')
assert log.text.contains('No PMD violations found in 2 files')
assert log.text.contains('CodeNarc not required')
assert log.text.contains('com.qulice.foo.Main.list is or uses a map or set of URLs, which can be a performance hog')
86 changes: 68 additions & 18 deletions qulice-ant/src/main/java/com/qulice/ant/AntEnvironment.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
/**
* Copyright (c) 2011-2014, Qulice.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the Qulice.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.qulice.ant;

import com.jcabi.log.Logger;
import com.qulice.spi.Environment;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
Expand All @@ -13,30 +41,50 @@
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.CollectionUtils;

/**
* Created with IntelliJ IDEA.
* User: alevohins
* Date: 03.01.15
* Time: 22:39
* To change this template use File | Settings | File Templates.
* Environment, passed from ant task to validators.
* @author Yuriy Alevohin (alevohin@mail.ru)
* @version $Id$
*/

public class AntEnvironment implements Environment {

/**
* Ant project.
*/
private transient final Project project;
private transient final Path sourcepath;

/**
* Sources dirs.
*/
private transient final Path srcdir;

/**
* Classes dir (only one dir is supported)
*/
private transient final java.io.File classesdir;

/**
* Classpath dirs and files.
*/
private transient final Path classpath;

/**
* Public constructor.
* @param project - ant project
* @param srcdir - sources dirs
* @param classesdir - classes dir
* @param classpath - classpath
*/
public AntEnvironment(
Project project,
Path sourcepath,
Path srcdir,
java.io.File classesdir,
Path classpath) {
this.project = project;
this.sourcepath = sourcepath;
this.srcdir = srcdir;
this.classesdir = classesdir;
this.classpath = classpath;
}

Expand All @@ -52,7 +100,7 @@ public File tempdir() {

@Override
public File outdir() {
return new File(this.basedir(), "classes");
return classesdir;
}

@Override
Expand All @@ -77,12 +125,14 @@ public ClassLoader classloader() {
throw new IllegalStateException("Failed to build URL", ex);
}
}
try {
urls.add(classesdir.toURI().toURL());
} catch (MalformedURLException ex) {
throw new IllegalStateException("Failed to build URL", ex);
}
final URLClassLoader loader = new URLClassLoader(
urls.toArray(new URL[urls.size()]),
// Thread.currentThread().getContextClassLoader()
project.getCoreLoader() == null ?
Thread.currentThread().getContextClassLoader() :
project.getCoreLoader()
Thread.currentThread().getContextClassLoader()
);
for (final URL url : loader.getURLs()) {
Logger.debug(this, "Classpath: %s", url);
Expand All @@ -99,7 +149,7 @@ public Collection<String> classpath() {
public Collection<File> files(String pattern) {
final Collection<File> files = new LinkedList<File>();
final IOFileFilter filter = new WildcardFileFilter(pattern);
for (final String dir : sourcepath.list()) {
for (final String dir : srcdir.list()) {
final File sources = new File(dir);
if (sources.exists() && sources.isDirectory()) {
files.addAll(
Expand Down
95 changes: 85 additions & 10 deletions qulice-ant/src/main/java/com/qulice/ant/QuliceTask.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,66 @@
/**
* Copyright (c) 2011-2014, Qulice.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the Qulice.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.qulice.ant;

import com.jcabi.log.Logger;
import com.qulice.spi.Environment;
import com.qulice.spi.ValidationException;
import com.qulice.spi.Validator;
import java.io.File;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;

/**
* Created with IntelliJ IDEA.
* User: alevohins
* Date: 03.01.15
* Time: 11:49
* To change this template use File | Settings | File Templates.
* Ant Task for Qulice.
*
* @author Yuriy Alevohin (alevohin@mail.ru)
* @version $Id$
*/
public class QuliceTask extends Task {

private transient Path sourcepath;
/**
* Sources dirs.
*/
private transient Path srcdir;

/**
* Classes dir (only one dir is supported)
*/
private transient File classesdir;

/**
* Classpath dirs and files.
*/
private transient Path classpath;

@Override
Expand All @@ -43,25 +84,43 @@ public void execute() throws BuildException {
}
}

/**
* Create Environment.
* @return Environment.
* @throws BuildException If ant task doesn't have mandatory params.
*/
private Environment environment() throws BuildException {
if (sourcepath == null) {
if (srcdir == null) {
throw new BuildException("sourcepath not defined for QuliceTask");
}
if (classesdir == null) {
throw new BuildException("classesdir not defined for QuliceTask");
}
if (classpath == null) {
throw new BuildException("classpath not defined for QuliceTask");
}
return new AntEnvironment(
getProject(),
sourcepath,
srcdir,
classesdir,
classpath);
}

/**
* Validate and throws exception if there are any problems.
* @param env Environment
* @throws ValidationException If there are any problems.
*/
private void validate(Environment env) throws ValidationException {
for (final Validator validator : this.validators()) {
validator.validate(env);
}
}

/**
* Create set of Validators.
* @return Set of Validators.
*/
private Set<Validator> validators() {
final Set<Validator> validators = new LinkedHashSet<Validator>();
validators.add(new com.qulice.checkstyle.CheckstyleValidator());
Expand All @@ -72,10 +131,26 @@ private Set<Validator> validators() {
return validators;
}

public void setSourcepath(Path sourcepath) {
this.sourcepath = sourcepath;
/**
* Set source dirs
* @param srcdir Source dirs
*/
public void setSrcdir(Path srcdir) {
this.srcdir = srcdir;
}

/**
* Set classes dir
* @param classesdir Classes dir
*/
public void setClassesdir(File classesdir) {
this.classesdir = classesdir;
}

/**
* Set classpath
* @param classpath classpath
*/
public void setClasspath(Path classpath) {
this.classpath = classpath;
}
Expand Down
2 changes: 1 addition & 1 deletion qulice-ant/src/main/java/com/qulice/ant/package-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2011-2015, Qulice.com
* Copyright (c) 2011-2014, Qulice.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down

0 comments on commit 884bd4f

Please sign in to comment.