-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dragoniade
committed
Apr 18, 2011
1 parent
d53156d
commit 6681f9f
Showing
43 changed files
with
6,932 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.dragoniade</groupId> | ||
<artifactId>da-favorite</artifactId> | ||
<version>1.2.0</version> | ||
<url>http://dafavdownloader.sourceforge.net</url> | ||
<name>deviantART Favorites Downloader</name> | ||
<description> | ||
An application that help you download and manage your favorites from the | ||
popular art site deviantART. | ||
</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>commons-httpclient</groupId> | ||
<artifactId>commons-httpclient</artifactId> | ||
<version>3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<version>1.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>xerces</groupId> | ||
<artifactId>xercesImpl</artifactId> | ||
<version>2.9.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>jaxen</groupId> | ||
<artifactId>jaxen</artifactId> | ||
<version>1.1-beta-9</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-eclipse-plugin</artifactId> | ||
<configuration> | ||
<downloadSources>true</downloadSources> | ||
<downloadJavadocs>true</downloadJavadocs> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.5</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<mainClass>com.dragoniade.deviantart.ui.DownloaderGUI</mainClass> | ||
<classpathPrefix>lib/</classpathPrefix> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>jar</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-dependencies</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${project.build.directory}/lib</outputDirectory> | ||
<overWriteReleases>false</overWriteReleases> | ||
<overWriteSnapshots>false</overWriteSnapshots> | ||
<overWriteIfNewer>true</overWriteIfNewer> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<descriptors> | ||
<descriptor>src/assemble/assemble.xml</descriptor> | ||
</descriptors> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<assembly | ||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> | ||
<id>zip</id> | ||
<formats> | ||
<format>zip</format> | ||
</formats> | ||
<fileSets> | ||
<fileSet> | ||
<directory>target/lib</directory> | ||
<outputDirectory>lib</outputDirectory> | ||
<includes> | ||
<include>*.jar</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>target</directory> | ||
<outputDirectory>/</outputDirectory> | ||
<includes> | ||
<include>*.jar</include> | ||
</includes> | ||
<excludes> | ||
<exclude>*-sources.jar</exclude> | ||
</excludes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>target</directory> | ||
<outputDirectory>src</outputDirectory> | ||
<includes> | ||
<include>*-sources.jar</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>src/main/resources</directory> | ||
<outputDirectory>/</outputDirectory> | ||
<includes> | ||
<include>*.ico</include> | ||
<include>README.txt</include> | ||
</includes> | ||
</fileSet> | ||
</fileSets> | ||
</assembly> |
175 changes: 175 additions & 0 deletions
175
Tags/1.2.0/src/main/java/com/dragoniade/clazz/ClassCrawler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/** | ||
* ClassCrawler - Craws the classpath and retrieve class mathching the | ||
* search criteria. | ||
* Copyright (C) 2009-2011 Philippe Busque | ||
* https://sourceforge.net/projects/dafavdownloader/ | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.dragoniade.clazz; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.net.URLDecoder; | ||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.Set; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.JarInputStream; | ||
|
||
|
||
|
||
public class ClassCrawler { | ||
|
||
|
||
private Set<String> prefixes; | ||
private Set<Class<?>> interfaces; | ||
private Set<Class<?>> superClasses; | ||
public ClassCrawler() { | ||
prefixes = new HashSet<String>(); | ||
interfaces = new HashSet<Class<?>>(); | ||
superClasses = new HashSet<Class<?>>(); | ||
} | ||
|
||
|
||
public void setInterfaces(Class<?> ... interfaces) { | ||
this.interfaces = new HashSet<Class<?>>(); | ||
for (Class<?> i: interfaces) { | ||
this.interfaces.add(i); | ||
} | ||
|
||
} | ||
|
||
public void setPrefixes(String ... prefixes) { | ||
this.prefixes = new HashSet<String>(); | ||
for (String p: prefixes) { | ||
this.prefixes.add(p); | ||
} | ||
} | ||
|
||
public void setSuperClasses(Class<?> ... superClasses) { | ||
this.superClasses = new HashSet<Class<?>>(); | ||
for (Class<?> s: superClasses) { | ||
this.superClasses.add(s); | ||
} | ||
} | ||
|
||
public Set<Class<?>> crawl() throws ClassNotFoundException { | ||
// URL [] urls = ((URLClassLoader)Thread.currentThread().getContextClassLoader()).getURLs(); | ||
URL [] urls = ((URLClassLoader)getClass().getClassLoader()).getURLs(); | ||
Set<Class<?>> classes = new HashSet<Class<?>>(); | ||
|
||
for (URL url: urls) { | ||
if (url.getProtocol().equals("file")) { | ||
if (url.getPath().endsWith(".jar") || url.getPath().endsWith(".zip")) { | ||
loadClassesFromJar(url,classes); | ||
} else { | ||
loadClassesFromFile(url,classes); | ||
} | ||
} | ||
if (url.getProtocol().equals("jar")) { | ||
loadClassesFromJar(url,classes); | ||
} | ||
} | ||
return classes; | ||
} | ||
private void loadClassesFromJar(URL url, Set<Class<?>> files ) throws ClassNotFoundException { | ||
try { | ||
InputStream stream = url.openStream(); | ||
|
||
JarInputStream fileNames = new JarInputStream(stream); | ||
JarEntry entry = null; | ||
while((entry =fileNames.getNextJarEntry()) != null) { | ||
if(entry.getName().endsWith(".class")) { | ||
add(files,entry.getName()); | ||
} | ||
} | ||
fileNames.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void loadClassesFromFile(URL url, Set<Class<?>> list ) throws ClassNotFoundException { | ||
|
||
LinkedList<File> fileList = new LinkedList<File>(); | ||
|
||
File urlFile; | ||
try { | ||
urlFile = new File(URLDecoder.decode(url.getPath(),"UTF-8")); | ||
} catch (UnsupportedEncodingException e) { | ||
urlFile = new File(url.getPath()); | ||
} | ||
String baseFile = urlFile.getPath(); | ||
fileList.add(urlFile); | ||
|
||
while (!fileList.isEmpty()) { | ||
File pop = fileList.removeFirst(); | ||
if (!pop.exists()) { | ||
continue; | ||
} | ||
File[] files = pop.listFiles(); | ||
|
||
for (File f: files) { | ||
if (f.isDirectory()) { | ||
fileList.add(f); | ||
} else { | ||
if (f.getName().endsWith(".class")) { | ||
add(list,f.getPath().substring(baseFile.length()+1)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void add(Set<Class<?>> list,String path) throws ClassNotFoundException { | ||
path = path.substring(0, path.length()-6); | ||
path = path.replace('/', '.').replaceAll("\\\\", "."); | ||
boolean isValid = false; | ||
if (prefixes.size() == 0) { | ||
isValid = true; | ||
} else { | ||
for (String prefix:prefixes) { | ||
if (path.startsWith(prefix)) { | ||
isValid = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (isValid) { | ||
try { | ||
Class<?> c = this.getClass().getClassLoader().loadClass(path); | ||
if (superClasses.size() > 0 ) { | ||
Class<?> superC = c.getSuperclass(); | ||
if (superClasses.contains(superC)) { | ||
list.add(c); | ||
return; | ||
} | ||
} | ||
if (interfaces.size() > 0) { | ||
for( Class<?> intC : c.getInterfaces() ) { | ||
if (interfaces.contains(intC)) { | ||
list.add(c); | ||
return; | ||
} | ||
} | ||
} | ||
} catch (Throwable e ) {} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Tags/1.2.0/src/main/java/com/dragoniade/clazz/SearcherClassCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.dragoniade.clazz; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import com.dragoniade.deviantart.deviation.Search; | ||
|
||
public class SearcherClassCache { | ||
|
||
private static SearcherClassCache instance; | ||
Set<Class<Search>> classes; | ||
|
||
@SuppressWarnings("unchecked") | ||
private SearcherClassCache () { | ||
ClassCrawler crawler = new ClassCrawler(); | ||
crawler.setInterfaces(Search.class); | ||
|
||
classes = new HashSet<Class<Search>>(); | ||
Set<Class<?>> list; | ||
try { | ||
list = crawler.crawl(); | ||
} catch (ClassNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
for( Class<?> clazz : list) { | ||
classes.add((Class<Search>) clazz); | ||
} | ||
} | ||
|
||
public Set<Class<Search>> getClasses() { | ||
return classes; | ||
} | ||
|
||
static public synchronized SearcherClassCache getInstance () { | ||
if (instance == null) { | ||
instance = new SearcherClassCache(); | ||
} | ||
return instance; | ||
} | ||
} |
Oops, something went wrong.