Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jan 5, 2012
0 parents commit 9ad0a47
Show file tree
Hide file tree
Showing 8 changed files with 591 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
.gradle
classloader.iml
classloader.ipr
classloader.iws
30 changes: 30 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'groovy'
apply plugin: 'idea'

slf4jVersion = '1.6.3'

repositories {
mavenCentral()
}

dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.8.5'
compile('log4j:log4j:1.2.16') {
exclude group: 'ant', module: 'ant-nodeps'
exclude group: 'ant', module: 'ant-junit'
exclude group: 'ant-contrib', module: 'ant-contrib'
}
compile("org.slf4j:slf4j-log4j12:$slf4jVersion") {
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'log4j', module: 'log4j'
}
compile("org.slf4j:slf4j-api:$slf4jVersion")
compile("org.slf4j:jcl-over-slf4j:$slf4jVersion") {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
compile("org.slf4j:jul-to-slf4j:$slf4jVersion") {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
compile('commons-lang:commons-lang:2.6')
testCompile 'junit:junit:4.10'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.
*/
package org.codehaus.griffon.classloader;

/**
* @author Andres Almiray
*/
public class ClasspathModule {
private final ClasspathModuleConfiguration configuration;
private final ClassLoader classLoader;
private boolean active = true;

public ClasspathModule(ClasspathModuleConfiguration configuration, ClassLoader classLoader) {
this.configuration = configuration;
this.classLoader = classLoader;
}

public String getName() {
return getConfiguration().getName();
}

public ClasspathModuleConfiguration getConfiguration() {
return configuration;
}

public ClassLoader getClassLoader() {
return classLoader;
}

public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed 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.
*/
package org.codehaus.griffon.classloader;

import java.net.URL;
import java.util.Arrays;

/**
* @author Andres Almiray
*/
public class ClasspathModuleConfiguration {
private final String name;
private final URL[] urls;
private final String toStringValue;
private final int hashCodeValue;

public ClasspathModuleConfiguration(String name, URL[] urls) {
this.urls = urls;
this.name = name;
this.toStringValue = "<" + name + ">" + Arrays.toString(urls);
this.hashCodeValue = computeHashCode();
}

public String getName() {
return name;
}

public URL[] getUrls() {
return urls;
}

public String toString() {
return toStringValue;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ClasspathModuleConfiguration)) return false;

ClasspathModuleConfiguration that = (ClasspathModuleConfiguration) o;

if (!name.equals(that.name)) return false;
if (!Arrays.equals(sort(urls), sort(that.urls))) return false;

return true;
}

@Override
public int hashCode() {
return hashCodeValue;
}

private URL[] sort(URL[] urls) {
URL[] copy = new URL[urls.length];
System.arraycopy(urls, 0, copy, 0, 0);
Arrays.sort(copy);
return copy;
}

private int computeHashCode() {
int result = name.hashCode();
result = 31 * result + Arrays.hashCode(urls);
return result;
}
}
Loading

0 comments on commit 9ad0a47

Please sign in to comment.