Fixed ripper discovery in JARs, moved to 1.7
...I think. Unit tests are passing so that's a good sign.
This commit is contained in:
parent
e2bb412d9f
commit
65d4b55cba
@ -1,4 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
|
||||
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
@ -6,7 +11,85 @@ org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deadCode=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
|
||||
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
|
||||
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
|
||||
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
@ -12,6 +13,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -227,42 +230,78 @@ public abstract class AbstractRipper
|
||||
return ripper;
|
||||
} catch (Exception e) {
|
||||
// Incompatible rippers *will* throw exceptions during instantiation.
|
||||
logger.error("Excepion while instantiating: " + constructor.getClass().getName(), e);
|
||||
//logger.error("Exception while instantiating: " + constructor.getName(), e);
|
||||
}
|
||||
}
|
||||
throw new Exception("No compatible ripper found");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets constructors for all rippers in the "ripper.rippers" package
|
||||
* @return list of constructors for all rippers.
|
||||
* @throws Exception
|
||||
*/
|
||||
private static List<Constructor<?>> getRipperConstructors() throws Exception {
|
||||
List<Constructor<?>> constructors = new ArrayList<Constructor<?>>();
|
||||
String rippersPackage = "com.rarchives.ripme.ripper.rippers";
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
Enumeration<URL> urls = cl.getResources(rippersPackage.replaceAll("\\.", "/"));
|
||||
if (!urls.hasMoreElements()) {
|
||||
return constructors;
|
||||
}
|
||||
URL classURL = urls.nextElement();
|
||||
for (File f : new File(classURL.toURI()).listFiles()) {
|
||||
String className = f.getName();
|
||||
if (!className.endsWith(".class")
|
||||
|| className.contains("$")
|
||||
|| className.endsWith("Test.class")) {
|
||||
// Ignore non-class or nested classes.
|
||||
continue;
|
||||
}
|
||||
className = className.substring(0, className.length() - 6); // Strip .class
|
||||
String fqname = rippersPackage + "." + className;
|
||||
Class<?> clazz = Class.forName(fqname);
|
||||
for (Class<?> clazz : getClassesForPackage("com.rarchives.ripme.ripper.rippers")) {
|
||||
if (AbstractRipper.class.isAssignableFrom(clazz)) {
|
||||
constructors.add( (Constructor<?>) clazz.getConstructor(URL.class) );
|
||||
}
|
||||
}
|
||||
return constructors;
|
||||
}
|
||||
|
||||
private static ArrayList<Class<?>> getClassesForPackage(String pkgname) {
|
||||
ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
String relPath = pkgname.replace('.', '/');
|
||||
URL resource = ClassLoader.getSystemClassLoader().getResource(relPath);
|
||||
if (resource == null) {
|
||||
throw new RuntimeException("No resource for " + relPath);
|
||||
}
|
||||
|
||||
String fullPath = resource.getFile();
|
||||
File directory = null;
|
||||
try {
|
||||
directory = new File(resource.toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(pkgname + " (" + resource + ") does not appear to be a valid URL / URI. Strange, since we got it from the system...", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
directory = null;
|
||||
}
|
||||
|
||||
if (directory != null && directory.exists()) {
|
||||
// Get the list of the files contained in the package
|
||||
String[] files = directory.list();
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".class") && !file.contains("$")) {
|
||||
String className = pkgname + '.' + file.substring(0, file.length() - 6);
|
||||
try {
|
||||
classes.add(Class.forName(className));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("ClassNotFoundException loading " + className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
|
||||
JarFile jarFile = new JarFile(jarPath);
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
String entryName = entries.nextElement().getName();
|
||||
if(entryName.startsWith(relPath)
|
||||
&& entryName.length() > (relPath.length() + "/".length())) {
|
||||
String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
|
||||
try {
|
||||
classes.add(Class.forName(className));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("ClassNotFoundException loading " + className);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(pkgname + " (" + directory + ") does not appear to be a valid package", e);
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
public void sendUpdate(STATUS status, Object message) {
|
||||
if (observer == null) {
|
||||
return;
|
||||
|
@ -46,7 +46,7 @@ public class ImgurRipperTest extends RippersTest {
|
||||
for (URL url : passURLs) {
|
||||
try {
|
||||
ImgurRipper ripper = new ImgurRipper(url);
|
||||
assertTrue(ripper.canRip(url));
|
||||
assert(ripper.canRip(url));
|
||||
deleteDir(ripper.getWorkingDir());
|
||||
} catch (Exception e) {
|
||||
fail("Failed to instantiate ripper for " + url);
|
||||
|
@ -7,7 +7,6 @@ import java.util.List;
|
||||
|
||||
import com.rarchives.ripme.ripper.rippers.InstagramRipper;
|
||||
|
||||
|
||||
public class InstagramRipperTest extends RippersTest {
|
||||
|
||||
public void testInstagramAlbums() throws IOException {
|
||||
|
@ -6,6 +6,11 @@ import junit.framework.TestCase;
|
||||
|
||||
public class RippersTest extends TestCase {
|
||||
|
||||
public void testNothing() {
|
||||
// Avoid complaints about no test cases in this file.
|
||||
assert(true);
|
||||
}
|
||||
|
||||
protected void deleteDir(File dir) {
|
||||
return;
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user