GemFile
*
* @param filename of the gem
* @return GemFile
*/
public GemFile gem(String filename) {
return factory.gemFile(filename.replaceFirst(".gem$", ""));
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/ApiV2File.java 0000664 0000000 0000000 00000002500 14467014544 0032547 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* for the only v2 API currently, /api/v2/rubygems/NAME/versions/VERSION.json
*/
public class ApiV2File
extends RubygemsFile {
private final String version;
ApiV2File(RubygemsFileFactory factory, String storage, String remote, String name, String version) {
super(factory, FileType.JSON_API, storage, remote, name);
this.version = version;
set(null);// no payload
}
/**
* the version of the gem
*/
public String version() {
return version;
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/BaseGemFile.java 0000664 0000000 0000000 00000005272 14467014544 0033142 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
public class BaseGemFile
extends RubygemsFile {
private final String filename;
private final String version;
private final String platform;
/**
* contructor using the full filename of a gem. there is no version nor platform info available
*/
BaseGemFile(RubygemsFileFactory factory, FileType type, String storage, String remote, String filename) {
this(factory, type, storage, remote, filename, null, null);
}
/**
* constructor using name, version and platform to build the filename of a gem
*/
BaseGemFile(RubygemsFileFactory factory, FileType type, String storage, String remote,
String name, String version, String platform) {
super(factory, type, storage, remote, name);
this.filename = toFilename(name, version, platform);
this.version = version;
this.platform = platform;
}
/**
* helper method to concatenate name
, version
* and platform
in the same manner as rubygems create filenames
* of gems.
*/
public static String toFilename(String name, String version, String platform) {
StringBuilder filename = new StringBuilder(name);
if (version != null) {
filename.append("-").append(version);
if (platform != null && !"ruby".equals(platform)) {
filename.append("-").append(platform);
}
}
return filename.toString();
}
/**
* the full filename of the gem
*/
public String filename() {
return filename;
}
/**
* the version of the gem
*
* @return can be null
*/
public String version() {
return version;
}
/**
* the platform of the gem
*
* @return can be null
*/
public String platform() {
return platform;
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/BundleRunner.java 0000664 0000000 0000000 00000005076 14467014544 0033444 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
import org.jruby.runtime.builtin.IRubyObject;
/**
* wrapper around the bundle
command using the a jruby ScriptingContainer
* to execute it.
*
* @author christian
*/
public class BundleRunner
extends ScriptWrapper {
/**
* @param ruby ScriptingContainer to use
*/
public BundleRunner(ScriptingContainer ruby) {
super(ruby, newScript(ruby));
}
/**
* create a new ruby object of the bundler command
*/
private static Object newScript(final ScriptingContainer scriptingContainer) {
IRubyObject runnerClass = scriptingContainer.parse(PathType.CLASSPATH, "nexus/bundle_runner.rb").run();
return scriptingContainer.callMethod(runnerClass, "new", IRubyObject.class);
}
/**
* execute bundle install
*
* @return STDOUT from the command execution as String
*/
public String install() {
return callMethod("exec", "install", String.class);
}
/**
* execute bundle show
*
* @return STDOUT from the command execution as String
*/
public String show() {
return callMethod("exec", "show", String.class);
}
/**
* execute bundle config
*
* @return STDOUT from the command execution as String
*/
public String config() {
return callMethod("exec", "config", String.class);
}
/**
* execute bundle show {gem-name}
*
* @param gemName to be passed to the show command
* @return STDOUT from the command execution as String
*/
public String show(String gemName) {
return callMethod("exec", new String[]{"show", gemName}, String.class);
}
}
mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/BundlerApiFile.java0000664 0000000 0000000 00000003353 14467014544 0033662 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import java.util.Arrays;
/**
* belongs to the path /api/v1/dependencies?gems=name1,name2, now backed by the compact index api at /info/gemname
*
* @author christian
*/
public class BundlerApiFile
extends RubygemsFile {
private final String[] names;
BundlerApiFile(RubygemsFileFactory factory, String remote, String... names) {
super(factory, FileType.BUNDLER_API, storageName(remote, names = sortedNames(names)), remote, null);
this.names = names;
}
private static String storageName(String remote, String[] names) {
return remote.replaceFirst("\\?gems=.*$", "/" + String.join("+", names) + ".gems");
}
private static String[] sortedNames(String[] names) {
String[] sorted = names.clone();
Arrays.sort(sorted);
return sorted;
}
/**
* names of gems from the query parameter 'gems'
*/
public String[] gemnames() {
return names;
}
} CompactInfoFile.java 0000664 0000000 0000000 00000002134 14467014544 0033754 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* for the new API, /info/GEM
*/
public class CompactInfoFile
extends RubygemsFile {
CompactInfoFile(RubygemsFileFactory factory, String storage, String remote, String name) {
super(factory, FileType.COMPACT, storage, remote, name);
set(null);// no payload
}
} DefaultRubygemsFileFactory.java 0000664 0000000 0000000 00000023333 14467014544 0036210 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import org.torquebox.mojo.rubygems.cuba.RootCuba;
import org.torquebox.mojo.rubygems.cuba.api.ApiCuba;
import org.torquebox.mojo.rubygems.cuba.api.ApiV1Cuba;
import org.torquebox.mojo.rubygems.cuba.api.ApiV1DependenciesCuba;
import org.torquebox.mojo.rubygems.cuba.gems.GemsCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenPrereleasesRubygemsArtifactIdCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenReleasesCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenReleasesRubygemsArtifactIdCuba;
import org.torquebox.mojo.rubygems.cuba.quick.QuickCuba;
import org.torquebox.mojo.rubygems.cuba.quick.QuickMarshalCuba;
import java.security.SecureRandom;
public class DefaultRubygemsFileFactory implements RubygemsFileFactory {
public static final String ID = "DefaultRubygemsFileFactory";
private static final String SEPARATOR = "/";
private static final String GEMS = "/" + RootCuba.GEMS;
private static final String QUICK_MARSHAL = "/" + RootCuba.QUICK + "/" + QuickCuba.MARSHAL_4_8;
private static final String API_V1 = "/" + RootCuba.API + "/" + ApiCuba.V1;
private static final String API_V2 = "/" + RootCuba.API + "/" + ApiCuba.V2;
@Deprecated
private static final String API_V1_DEPS = API_V1 + "/" + ApiV1Cuba.DEPENDENCIES;
private static final String API_V2_RUBYGEMS = API_V2 + "/rubygems";
private static final String INFO = "info";
private static final String MAVEN_PRERELEASED_RUBYGEMS = "/" + RootCuba.MAVEN + "/" + MavenCuba.PRERELEASES + "/" + MavenReleasesCuba.RUBYGEMS;
private static final String MAVEN_RELEASED_RUBYGEMS = "/" + RootCuba.MAVEN + "/" + MavenCuba.RELEASES + "/" + MavenReleasesCuba.RUBYGEMS;
private final static SecureRandom random = new SecureRandom();
static {
random.setSeed(System.currentTimeMillis());
}
private String join(String... parts) {
return String.join("", parts);
}
private String toPath(String name, String version, String timestamp, boolean snapshot) {
String v1 = snapshot ? version + "-" + timestamp : version;
String v2 = snapshot ? version + MavenPrereleasesRubygemsArtifactIdCuba.SNAPSHOT : version;
return join(snapshot ? MAVEN_PRERELEASED_RUBYGEMS : MAVEN_RELEASED_RUBYGEMS, SEPARATOR, name, SEPARATOR, v2, SEPARATOR, name + '-' + v1);
}
@Override
public Sha1File sha1(RubygemsFile file) {
return new Sha1File(this, file.storagePath() + ".sha1", file.remotePath() + ".sha1", file);
}
@Override
public NoContentFile noContent(final String path) {
return new NoContentFile(this, path);
}
@Override
public NotFoundFile notFound(String path) {
return new NotFoundFile(this, path);
}
@Override
public PomFile pomSnapshot(String name, String version, String timestamp) {
return new PomFile(this, toPath(name, version, timestamp, true) + ".pom", name, version, true);
}
@Override
public GemArtifactFile gemArtifactSnapshot(String name, String version, String timestamp) {
return new GemArtifactFile(this, toPath(name, version, timestamp, true) + ".gem", name, version, true);
}
@Override
public PomFile pom(String name, String version) {
return new PomFile(this, toPath(name, version, null, false) + ".pom", name, version, false);
}
@Override
public GemArtifactFile gemArtifact(String name, String version) {
return new GemArtifactFile(this, toPath(name, version, null, false) + ".gem", name, version, false);
}
@Override
public MavenMetadataSnapshotFile mavenMetadataSnapshot(String name, String version) {
String path = join(MAVEN_PRERELEASED_RUBYGEMS, SEPARATOR, name, SEPARATOR, version + MavenPrereleasesRubygemsArtifactIdCuba.SNAPSHOT, SEPARATOR, MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML);
return new MavenMetadataSnapshotFile(this, path, name, version);
}
@Override
public MavenMetadataFile mavenMetadata(String name, boolean prereleased) {
String path = join(prereleased ? MAVEN_PRERELEASED_RUBYGEMS : MAVEN_RELEASED_RUBYGEMS, SEPARATOR, name, SEPARATOR, MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML);
return new MavenMetadataFile(this, path, name, prereleased);
}
@Override
public Directory directory(String path, String... items) {
if (!path.endsWith("/")) {
path += "/";
}
return new Directory(this, path,
// that is the name
path.substring(0, path.length() - 1).replaceFirst(".*\\/", ""), items);
}
@Override
public RubygemsDirectory rubygemsDirectory(String path) {
if (!path.endsWith("/")) {
path += "/";
}
return new RubygemsDirectory(this, path);
}
@Override
public GemArtifactIdDirectory gemArtifactIdDirectory(String path, String name, boolean prereleases) {
if (!path.endsWith("/")) {
path += "/";
}
return new GemArtifactIdDirectory(this, path, name, prereleases);
}
@Override
public Directory gemArtifactIdVersionDirectory(String path, String name, String version, boolean prerelease) {
if (!path.endsWith("/")) {
path += "/";
}
return new GemArtifactIdVersionDirectory(this, path, name, version, prerelease);
}
@Override
public GemFile gemFile(String name, String version, String platform) {
String filename = BaseGemFile.toFilename(name, version, platform);
return new GemFile(this, join(GEMS, SEPARATOR, name.substring(0, 1), SEPARATOR, filename, GemsCuba.GEM), join(GEMS, SEPARATOR, filename, GemsCuba.GEM), name, version, platform);
}
@Override
public GemFile gemFile(String name) {
return new GemFile(this, join(GEMS, SEPARATOR, name.substring(0, 1), SEPARATOR, name, GemsCuba.GEM), join(GEMS, SEPARATOR, name, GemsCuba.GEM), name);
}
@Override
public GemspecFile gemspecFile(String name, String version, String platform) {
return new GemspecFile(this, join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), name, version, platform);
}
@Override
public GemspecFile gemspecFile(String name) {
return new GemspecFile(this, join(QUICK_MARSHAL, SEPARATOR, name.substring(0, 1), SEPARATOR, name, QuickMarshalCuba.GEMSPEC_RZ), join(QUICK_MARSHAL, SEPARATOR, name, QuickMarshalCuba.GEMSPEC_RZ), name);
}
@Override
@Deprecated
public DependencyFile dependencyFile(String name) {
return new DependencyFile(this, join(API_V1_DEPS, SEPARATOR, name, ApiV1DependenciesCuba.RUBY), join(API_V1_DEPS, "?gems=" + name), name);
}
@Override
public ApiV2File rubygemsInfoV2(String name, String version) {
return new ApiV2File(this, join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), join(API_V2_RUBYGEMS, SEPARATOR, name, SEPARATOR, "versions", SEPARATOR, version, ".json"), name, version);
}
@Override
public CompactInfoFile compactInfo(String name) {
return new CompactInfoFile(this, join("/info", SEPARATOR, name, ".compact"), join("/info", SEPARATOR, name), name);
}
@Override
public BundlerApiFile bundlerApiFile(String names) {
// normalize query string first
names = names.replaceAll("%2C", ",").replaceAll(",,", ",").replaceAll("\\s+", "").replaceAll(",\\s*$", "");
return new BundlerApiFile(this, join(API_V1_DEPS, "?gems=" + names), names.split(","));
}
@Override
public BundlerApiFile bundlerApiFile(String... names) {
StringBuilder gems = new StringBuilder("?gems=");
boolean first = true;
for (String name : names) {
if (first) {
first = false;
} else {
gems.append(",");
}
gems.append(name);
}
return new BundlerApiFile(this, join(API_V1_DEPS, gems.toString()), names);
}
@Override
public ApiV1File apiV1File(String name) {
return new ApiV1File(this, join(API_V1, SEPARATOR, Long.toString(Math.abs(random.nextLong())), ".", name), join(API_V1, SEPARATOR, name), name);
}
@Override
public SpecsIndexFile specsIndexFile(SpecsIndexType type) {
return this.specsIndexFile(type.filename().replace(RootCuba._4_8, ""));
}
@Override
public SpecsIndexFile specsIndexFile(String name) {
return new SpecsIndexFile(this, join(SEPARATOR, name, RootCuba._4_8), name);
}
@Override
public SpecsIndexZippedFile specsIndexZippedFile(String name) {
return new SpecsIndexZippedFile(this, join(SEPARATOR, name, RootCuba._4_8, RootCuba.GZ), name);
}
@Override
public SpecsIndexZippedFile specsIndexZippedFile(SpecsIndexType type) {
return this.specsIndexZippedFile(type.filename().replace(RootCuba._4_8, ""));
}
}
DefaultRubygemsGateway.java 0000664 0000000 0000000 00000011572 14467014544 0035404 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import org.jruby.RubyInstanceConfig;
import org.jruby.embed.ScriptingContainer;
import java.io.InputStream;
public class DefaultRubygemsGateway
implements RubygemsGateway {
private final ScriptingContainer container;
private Object dependencyHelperImplClass;
private Object gemspecHelperImplClass;
private Object specsHelperImplClass;
private Object mergeSpecsHelperImplClass;
private Object dependencyDataImplClass;
private Object rubygemsV2GemInfoImplClass;
private Object compactDependencyDataImplClass;
/**
* Ctor that accepts prepared non-null scripting container.
*/
public DefaultRubygemsGateway(final ScriptingContainer container) {
this.container = container;
this.container.setCompileMode(RubyInstanceConfig.CompileMode.OFF);
dependencyHelperImplClass = container.runScriptlet("require 'nexus/dependency_helper_impl';"
+ "Nexus::DependencyHelperImpl");
gemspecHelperImplClass = container.runScriptlet("require 'nexus/gemspec_helper_impl';"
+ "Nexus::GemspecHelperImpl");
specsHelperImplClass = container.runScriptlet("require 'nexus/specs_helper_impl';"
+ "Nexus::SpecsHelperImpl");
mergeSpecsHelperImplClass = container.runScriptlet("require 'nexus/merge_specs_helper_impl';"
+ "Nexus::MergeSpecsHelperImpl");
dependencyDataImplClass = container.runScriptlet("require 'nexus/dependency_data_impl';"
+ "Nexus::DependencyDataImpl");
rubygemsV2GemInfoImplClass = container.runScriptlet("require 'nexus/rubygems_v2_gem_info_impl';"
+ "Nexus::RubygemsV2GemInfoImpl");
compactDependencyDataImplClass = container.runScriptlet("require 'nexus/compact_dependency_data';"
+ "Nexus::CompactDependencyData");
}
@Override
public void terminate() {
dependencyHelperImplClass = null;
gemspecHelperImplClass = null;
specsHelperImplClass = null;
mergeSpecsHelperImplClass = null;
dependencyDataImplClass = null;
rubygemsV2GemInfoImplClass = null;
compactDependencyDataImplClass = null;
container.terminate();
}
@Override
public SpecsHelper newSpecsHelper() {
return container.callMethod(specsHelperImplClass, "new", SpecsHelper.class);
}
@Override
public MergeSpecsHelper newMergeSpecsHelper() {
return container.callMethod(mergeSpecsHelperImplClass, "new", MergeSpecsHelper.class);
}
@Override
public DependencyHelper newDependencyHelper() {
return container.callMethod(dependencyHelperImplClass, "new", DependencyHelper.class);
}
@Override
public GemspecHelper newGemspecHelper(InputStream gemspec) {
return container.callMethod(gemspecHelperImplClass, "from_gemspec_rz", gemspec, GemspecHelper.class);
}
@Override
public GemspecHelper newGemspecHelperFromGem(InputStream gem) {
return container.callMethod(gemspecHelperImplClass, "from_gem", gem, GemspecHelper.class);
}
@Override
public GemspecHelper newGemspecHelperFromV2GemInfo(InputStream gem) {
return container.callMethod(gemspecHelperImplClass, "from_rubygems_v2_gem_info", gem, GemspecHelper.class);
}
@Override
public DependencyData newDependencyData(InputStream dependency, String name, long modified) {
return container.callMethod(dependencyDataImplClass, "new", new Object[]{dependency, name, modified},
DependencyData.class);
}
@Override
public RubygemsV2GemInfo newRubygemsV2GemInfo(InputStream apiV2FileIS, String name, String version, long modified) {
return container.callMethod(rubygemsV2GemInfoImplClass, "new", new Object[]{apiV2FileIS, name, version, modified},
RubygemsV2GemInfo.class);
}
@Override
public DependencyData newCompactDependencyData(InputStream dependency, String name, long modified) {
return container.callMethod(compactDependencyDataImplClass, "new", new Object[]{dependency, name, modified},
DependencyData.class);
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/DependencyData.java0000664 0000000 0000000 00000003224 14467014544 0033702 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* abstract the info of ONE gem which is delivered by
* bundler API via /api/v1/dependencies?gems=n1,n2
* * all the versions collected are jruby compatible. *
* retrieve the right java compatible platform * for a gem version. *
* with an extra modified attribute to build the right timestamp.
*
* @author christian
*/
public interface DependencyData {
/**
* all available versions of the a gem
*
* @return String[] all JRuby compatible versions
*/
String[] versions(boolean prereleased);
/**
* retrieve the rubygems platform for a given version
*
* @return either the platform of the null
*/
String platform(String version);
/**
* the name of the gem
*/
String name();
/**
* when was the version data last modified.
*/
long modified();
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/DependencyFile.java0000664 0000000 0000000 00000002264 14467014544 0033713 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* represents /api/v1/dependencies/{name}.ruby
* where the file content is the response of /api/v1/dependencies?gems={name}
*
* @author christian
*/
public class DependencyFile
extends RubygemsFile {
DependencyFile(RubygemsFileFactory factory, String storage, String remote, String name) {
super(factory, FileType.DEPENDENCY, storage, remote, name);
}
} DependencyHelper.java 0000664 0000000 0000000 00000005476 14467014544 0034204 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
* helper to collect or merge dependency data from DependencyFile
s
* or extract the dependency data from a given GemspecFile
.
* the remote data from BundlerApiFile
is collection of the same
* dependency data format which can added as well.
*
* after adding all the data, you can retrieve the list of gemnames for which
* there are dependency data and retrieve them as marshalled stream (same format as
* DependencyFile
or BundlerApiFile
).
*
* @author christian
*/
public interface DependencyHelper {
/**
* add dependency data to instance
*
* @param marshalledDependencyData stream of the marshalled "ruby" data
*/
void add(InputStream marshalledDependencyData);
/**
* add dependency data to instance
*
* @param compactInfo stream of compact info for the given gem
* @param name the name of the gem
* @param modified last modified date of the compact info
*/
void addCompact(InputStream compactInfo, String name, long modified);
/**
* add dependency data to instance from a rzipped gemspec object.
*
* @param gemspec rzipped stream of the marshalled gemspec object
*/
void addGemspec(InputStream gemspec);
/**
* freezes the instance - no more added of data is allowed - and returns
* the list of gemnames for which dependency data was added.
*
* @return String[] of gemnames
*/
String[] getGemnames();
/**
* marshal ruby object with dependency data for the given gemname.
*
* @param gemname
* @return ByteArrayInputStream of binary data
*/
ByteArrayInputStream getInputStreamOf(String gemname);
/**
* marshal ruby object with dependency data for all the dependency data,
* either with or without duplicates.
*
* @return ByteArrayInputStream of binary data
*/
ByteArrayInputStream getInputStream(boolean unique);
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/Directory.java 0000664 0000000 0000000 00000003225 14467014544 0032777 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* represents a directory with entries/items
*
* has no payload.
*
* @author christian
*/
public class Directory
extends RubygemsFile {
/**
* directory items
*/
final List
* they all carry the mime-type, the encoding and a varyAccept boolean.
*
* @author christian
*/
public enum FileType {
GEM("binary/octet-stream", true),
GEMSPEC("binary/octet-stream", true),
DEPENDENCY("application/octet-stream", true),
MAVEN_METADATA("application/xml", "utf-8", true),
MAVEN_METADATA_SNAPSHOT("application/xml", "utf-8", true),
POM("application/xml", "utf-8", true),
SPECS_INDEX("application/octet-stream", true),
SPECS_INDEX_ZIPPED("application/x-gzip", true),
DIRECTORY("text/html", "utf-8"),
BUNDLER_API("application/octet-stream", true),
API_V1("text/plain", "ASCII"), // for the api_key
GEM_ARTIFACT("binary/octet-stream", true),
SHA1("text/plain", "ASCII"),
NOT_FOUND(null),
FORBIDDEN(null),
TEMP_UNAVAILABLE(null),
NO_CONTENT("text/plain"),
JSON_API("text/plain", "utf-8"),
COMPACT("test/plain", "utf-8");
private final String encoding;
private final String mime;
private final boolean varyAccept;
private FileType(String mime) {
this(mime, null, false);
}
private FileType(String mime, boolean varyAccept) {
this(mime, null, varyAccept);
}
private FileType(String mime, String encoding) {
this(mime, encoding, false);
}
private FileType(String mime, String encoding, boolean varyAccept) {
this.mime = mime;
this.encoding = encoding;
this.varyAccept = varyAccept;
}
public boolean isVaryAccept() {
return varyAccept;
}
public String encoding() {
return encoding;
}
public String mime() {
return this.mime;
}
}
GemArtifactFile.java 0000664 0000000 0000000 00000004607 14467014544 0033747 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
public class GemArtifactFile
extends RubygemsFile {
private final String version;
private final boolean snapshot;
private GemFile gem;
GemArtifactFile(RubygemsFileFactory factory,
String path,
String name,
String version,
boolean snapshot) {
super(factory, FileType.GEM_ARTIFACT, path, path, name);
this.version = version;
this.snapshot = snapshot;
}
/**
* the version of the gem
*/
public String version() {
return version;
}
/**
* whether it is a snapshot or not
*/
public boolean isSnapshot() {
return snapshot;
}
/**
* is lazy state of the associated GemFile. the GemFile needs to
* have the right platform for which the {@link RubygemsV2GemInfo} is needed
* to retrieve this platform. a second call can be done without RubygemsV2GemInfo !
*
* @param dependencies can be null
* @return the associated GemFile - can be null if RubygemsV2GemInfo was never passed in
*/
public GemFile gem(DependencyData dependencies) {
if (this.gem == null && dependencies != null) {
String platform = dependencies.platform(version());
if (platform != null) {
this.gem = factory.gemFile(name(), version(), platform);
}
}
return this.gem;
}
/**
* the associated DependencyFile object for the gem-artifact
*/
public CompactInfoFile dependency() {
return factory.compactInfo(name());
}
} GemArtifactIdDirectory.java 0000664 0000000 0000000 00000004071 14467014544 0035304 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import java.util.Arrays;
/**
* represent /maven/releases/rubygems/{artifactId} or /maven/prereleases/rubygems/{artifactId}
*
* @author christian
*/
public class GemArtifactIdDirectory
extends Directory {
private final boolean prereleased;
GemArtifactIdDirectory(RubygemsFileFactory factory, String path, String name, boolean prereleased) {
super(factory, path, name);
items.add("maven-metadata.xml");
items.add("maven-metadata.xml.sha1");
this.prereleased = prereleased;
}
/**
* whether to show prereleased or released gems inside the directory
*/
public boolean isPrerelease() {
return prereleased;
}
/**
* the
* you can pass in a payload which is meant to retrieve the actual content of the underlying file from the local
* storage. the payload can be an exception which also sets the state to ERROR.
*
* beside the PAYLOAD and ERROR state it can have other states: NOT_EXISTS, NO_PAYLOAD, TEMP_UNAVAILABLE, FORBIDDEN
*
* @author christian
*/
public class RubygemsFile {
/**
* factory to create associated objects
*/
final RubygemsFileFactory factory;
private final String name;
private final String storage;
private final String remote;
private final FileType type;
private Object payload;
private State state = State.NEW_INSTANCE;
RubygemsFile(RubygemsFileFactory factory, FileType type, String storage, String remote, String name) {
this.factory = factory;
this.type = type;
this.storage = storage;
this.remote = remote;
this.name = name;
}
/**
* name of the file - meaning of name depends on file-type
*/
public String name() {
return name;
}
/**
* local path of the file
*/
public String storagePath() {
return storage;
}
/**
* remote path of the file
*/
public String remotePath() {
return remote;
}
/**
* type of the file
*/
public FileType type() {
return type;
}
/**
* state of the file
*/
public State state() {
return state;
}
protected void addToString(StringBuilder builder) {
builder.append("type=").append(type.name())
.append(", storage=").append(storage)
.append(", remote=").append(remote);
if (name != null) {
builder.append(", name=").append(name);
}
builder.append(", state=").append(state.name());
if (state == State.ERROR) {
builder.append(", exception=").append(getException().getClass().getSimpleName())
.append(": ").append(getException().getMessage());
} else if (state == State.PAYLOAD) {
builder.append(", payload=").append(get().toString());
}
}
public String toString() {
StringBuilder builder = new StringBuilder("RubygemsFile[");
addToString(builder);
builder.append("]");
return builder.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((remote == null) ? 0 : remote.hashCode());
result = prime * result
+ ((storage == null) ? 0 : storage.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
RubygemsFile other = (RubygemsFile) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (remote == null) {
if (other.remote != null) {
return false;
}
} else if (!remote.equals(other.remote)) {
return false;
}
if (storage == null) {
if (other.storage != null) {
return false;
}
} else if (!storage.equals(other.storage)) {
return false;
}
if (type != other.type) {
return false;
}
return true;
}
/**
* retrieve the payload - whatever was set via {@link RubygemsFile#set(Object)} or
* {@link RubygemsFile#setException(Exception)}
*/
public Object get() {
return payload;
}
/**
* sets the payload and set the state to NO_PAYLOAD or PAYLOAD respectively
*/
public void set(Object payload) {
state = payload == null ? State.NO_PAYLOAD : State.PAYLOAD;
this.payload = payload;
}
/**
* retrieve the exception if state == ERROR otherwise null
*/
public Exception getException() {
if (hasException()) {
return (Exception) payload;
} else {
return null;
}
}
/**
* sets the state to ERROR and the exception as payload
*
* @param e (should not be null)
*/
public void setException(Exception e) {
set(e);
state = State.ERROR;
}
/**
* true if state == ERROR
*/
public boolean hasException() {
return state == State.ERROR;
}
/**
* reset the payload and state to NEW_INSTANCE - same as newly constructed object
*/
public void resetState() {
payload = null;
state = State.NEW_INSTANCE;
}
/**
* any state member of NEW_INSTANCE, NO_PAYLOAD, State.PAYLOAD will return true
*/
public boolean exists() {
return state == State.NEW_INSTANCE || state == State.NO_PAYLOAD || state == State.PAYLOAD;
}
/**
* state == NOT_EXISTS
*/
public boolean notExists() {
return state == State.NOT_EXISTS;
}
/**
* state == NO_PAYLOAD
*/
public boolean hasNoPayload() {
return state == State.NO_PAYLOAD;
}
/**
* state == PAYLOAD
*/
public boolean hasPayload() {
return state == State.PAYLOAD;
}
/**
* state == FORBIDDEN
*/
public boolean forbidden() {
return state == State.FORBIDDEN;
}
/**
* make file as not existing (state = NOT_EXISTS)
*/
public void markAsNotExists() {
state = State.NOT_EXISTS;
}
/**
* make file as temporary unavailable (state = TEMP_UNAVAILABLE)
*/
public void markAsTempUnavailable() {
state = State.TEMP_UNAVAILABLE;
}
/**
* make file as forbidden (state = FORBIDDEN)
*/
public void markAsForbidden() {
state = State.FORBIDDEN;
}
public static enum State {
NEW_INSTANCE, NOT_EXISTS, ERROR, NO_PAYLOAD, TEMP_UNAVAILABLE, FORBIDDEN, PAYLOAD
}
}
RubygemsFileFactory.java 0000664 0000000 0000000 00000016615 14467014544 0034710 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* interface for a factory to create
* it only returns the new specs index if it changes, i.e. if the given spec did not exsists in the specs index
* then a
* this method keeps a state and is meant to be called with all three specs-index types and with 'latest' type
* at the end. in can happen that the latest spec index needs to reconstructed from release specs index
* for this the release spec index remains as state of the class until the call with latest specs index is done.
*
* @param spec a Gem::Specification ruby object
* @param specsIndex the
* it is basically the static part of the
* files [specs.4.8, latest_specs.4.8, prerelease_specs.4.8, specs.4.8.gz, latest_specs.4.8.gz,
* prerelease_specs.4.8.gz]
*/
public RubygemsFile on(State state) {
switch (state.name) {
case API:
return state.nested(api);
case QUICK:
return state.nested(quick);
case GEMS:
return state.nested(gems);
case MAVEN:
return state.nested(maven);
case INFO:
return state.nested(info);
case "":
return state.context.factory.directory(state.context.original, "api/", "quick/", "gems/", "maven/", "specs.4.8", "latest_specs.4.8", "prerelease_specs.4.8", "specs.4.8.gz", "latest_specs.4.8.gz", "prerelease_specs.4.8.gz");
default:
}
Matcher m = SPECS.matcher(state.name);
if (m.matches()) {
if (m.group(3) == null) {
return state.context.factory.specsIndexFile(m.group(1));
}
return state.context.factory.specsIndexZippedFile(m.group(1));
}
return state.context.factory.notFound(state.context.original);
}
} RubygemsFileSystem.java 0000664 0000000 0000000 00000007464 14467014544 0035501 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba;
import org.torquebox.mojo.rubygems.FileType;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.RubygemsFileFactory;
import org.torquebox.mojo.rubygems.layout.Layout;
import java.io.InputStream;
public class RubygemsFileSystem {
private final Cuba cuba;
private final RubygemsFileFactory factory;
private final Layout getLayout;
private final Layout postLayout;
private final Layout deleteLayout;
protected RubygemsFileSystem(RubygemsFileFactory factory,
Layout getLayout,
Layout postLayout,
Layout deleteLayout,
Cuba cuba) {
this.cuba = cuba;
this.factory = factory;
this.getLayout = getLayout;
this.postLayout = postLayout;
this.deleteLayout = deleteLayout;
}
public RubygemsFile file(String path) {
return visit(factory, path, null);
}
public RubygemsFile file(String path, String query) {
return visit(factory, path, query);
}
public RubygemsFile get(String path) {
return visit(getLayout, path, null);
}
public RubygemsFile get(String path, String query) {
return visit(getLayout, path, query);
}
private RubygemsFile visit(RubygemsFileFactory factory, String originalPath, String query) {
//normalize PATH-Separator from Windows platform to valid URL-Path
// https://github.com/sonatype/nexus-ruby-support/issues/38
originalPath = originalPath.replace('\\', '/');
if (!originalPath.startsWith("/")) {
originalPath = "/" + originalPath;
}
String path = originalPath;
if (query == null) {
if (originalPath.contains("?")) {
int index = originalPath.indexOf("?");
if (index > -1) {
query = originalPath.substring(index + 1);
path = originalPath.substring(0, index);
}
} else {
query = "";
}
}
return new State(new Context(factory, originalPath, query), path, null).nested(cuba);
}
public RubygemsFile post(InputStream is, String path) {
if (postLayout != null) {
RubygemsFile file = visit(postLayout, path, "");
if (!file.forbidden() && file.type() != FileType.NOT_FOUND) {
post(is, file);
}
return file;
}
RubygemsFile file = visit(factory, path, "");
file.markAsForbidden();
return file;
}
public void post(InputStream is, RubygemsFile file) {
postLayout.addGem(is, file);
}
public RubygemsFile delete(String path) {
return visit(deleteLayout, path, "");
}
public String toString() {
StringBuilder b = new StringBuilder(getClass().getSimpleName());
b.append("<").append(cuba.getClass().getSimpleName()).append(">");
return b.toString();
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/State.java 0000664 0000000 0000000 00000004723 14467014544 0033031 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba;
import org.torquebox.mojo.rubygems.RubygemsFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* this is the
* it can be visited by a
* if there is query string with "gems" parameter then
* otherwise all {name}.ruby will be created as
* the directory itself does not produce the directory listing - only the empty
* create
* the directory itself does not produce the directory listing - only the empty
* files [maven-metadata.xml,maven-metadata.xml.sha1]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML:
return state.context.factory.mavenMetadata(name, true);
case MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML + ".sha1":
MavenMetadataFile file = state.context.factory.mavenMetadata(name, true);
return state.context.factory.sha1(file);
case "":
return state.context.factory.gemArtifactIdDirectory(state.context.original, name, true);
default:
return state.nested(new MavenPrereleasesRubygemsArtifactIdVersionCuba(name,
state.name.replace(SNAPSHOT, "")));
}
}
} MavenPrereleasesRubygemsArtifactIdVersionCuba.java 0000664 0000000 0000000 00000006656 14467014544 0044062 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.MavenMetadataSnapshotFile;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* cuba for /maven/prereleases/rubygems/{artifactId}/{version}-SNAPSHOT/
*
* @author christian
*/
public class MavenPrereleasesRubygemsArtifactIdVersionCuba
implements Cuba {
private static final Pattern FILE = Pattern.compile("^.*?([^-][^-]*)\\.(gem|pom|gem.sha1|pom.sha1)$");
private final String artifactId;
private final String version;
public MavenPrereleasesRubygemsArtifactIdVersionCuba(String artifactId, String version) {
this.artifactId = artifactId;
this.version = version;
}
/**
* directories one for each version of the gem with given name/artifactId
*
* files [{artifactId}-{version}-SNAPSHOT.gem,{artifactId}-{version}-SNAPSHOT.gem.sha1,
* {artifactId}-{version}-SNAPSHOT.pom,{artifactId}-{version}-SNAPSHOT.pom.sha1]
*/
@Override
public RubygemsFile on(State state) {
Matcher m = FILE.matcher(state.name);
if (m.matches()) {
switch (m.group(2)) {
case "gem":
return state.context.factory.gemArtifactSnapshot(artifactId, version, m.group(1));
case "pom":
return state.context.factory.pomSnapshot(artifactId, version, m.group(1));
case "gem.sha1":
RubygemsFile file = state.context.factory.gemArtifactSnapshot(artifactId, version, m.group(1));
return state.context.factory.sha1(file);
case "pom.sha1":
file = state.context.factory.pomSnapshot(artifactId, version, m.group(1));
return state.context.factory.sha1(file);
default:
}
}
switch (state.name) {
case MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML:
return state.context.factory.mavenMetadataSnapshot(artifactId, version);
case MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML + ".sha1":
MavenMetadataSnapshotFile file = state.context.factory.mavenMetadataSnapshot(artifactId, version);
return state.context.factory.sha1(file);
case "":
return state.context.factory.gemArtifactIdVersionDirectory(state.context.original, artifactId, version, true);
default:
return state.context.factory.notFound(state.context.original);
}
}
} MavenPrereleasesRubygemsCuba.java 0000664 0000000 0000000 00000002657 14467014544 0040556 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /maven/prereleases/rubygems/
*
* @author christian
*/
public class MavenPrereleasesRubygemsCuba
implements Cuba {
/**
* directories one for each gem (name without version)
*/
@Override
public RubygemsFile on(State ctx) {
if (ctx.name.isEmpty()) {
return ctx.context.factory.rubygemsDirectory(ctx.context.original);
}
return ctx.nested(new MavenPrereleasesRubygemsArtifactIdCuba(ctx.name));
}
} MavenReleasesCuba.java 0000664 0000000 0000000 00000003407 14467014544 0036323 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /maven/releases/
*
* @author christian
*/
public class MavenReleasesCuba
implements Cuba {
public static final String RUBYGEMS = "rubygems";
private final Cuba mavenReleasesRubygems;
public MavenReleasesCuba(Cuba mavenReleasesRubygems) {
this.mavenReleasesRubygems = mavenReleasesRubygems;
}
/**
* directory [rubygems]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case MavenReleasesCuba.RUBYGEMS:
return state.nested(mavenReleasesRubygems);
case "":
return state.context.factory.directory(state.context.original, MavenReleasesCuba.RUBYGEMS);
default:
return state.context.factory.notFound(state.context.original);
}
}
} MavenReleasesRubygemsArtifactIdCuba.java 0000664 0000000 0000000 00000004430 14467014544 0041771 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.MavenMetadataFile;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /maven/releases/rubygems/{artifactId}
*
* @author christian
*/
public class MavenReleasesRubygemsArtifactIdCuba
implements Cuba {
public static final String MAVEN_METADATA_XML = "maven-metadata.xml";
private final String artifactId;
public MavenReleasesRubygemsArtifactIdCuba(String artifactId) {
this.artifactId = artifactId;
}
/**
* directories one for each version of the gem with given name/artifactId
*
* files [maven-metadata.xml,maven-metadata.xml.sha1]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML:
return state.context.factory.mavenMetadata(artifactId, false);
case MavenReleasesRubygemsArtifactIdCuba.MAVEN_METADATA_XML + ".sha1":
MavenMetadataFile file = state.context.factory.mavenMetadata(artifactId, false);
return state.context.factory.sha1(file);
case "":
return state.context.factory.gemArtifactIdDirectory(state.context.original, artifactId, false);
default:
return state.nested(new MavenReleasesRubygemsArtifactIdVersionCuba(artifactId, state.name));
}
}
} MavenReleasesRubygemsArtifactIdVersionCuba.java 0000664 0000000 0000000 00000005500 14467014544 0043336 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* cuba for /maven/prereleases/rubygems/{artifactId}/{version}/
*
* @author christian
*/
public class MavenReleasesRubygemsArtifactIdVersionCuba
implements Cuba {
private static final Pattern FILE = Pattern.compile("^.*\\.(gem|pom|gem.sha1|pom.sha1)$");
private final String artifactId;
private final String version;
public MavenReleasesRubygemsArtifactIdVersionCuba(String artifactId, String version) {
this.artifactId = artifactId;
this.version = version;
}
/**
* directories one for each version of the gem with given name/artifactId
*
* files [{artifactId}-{version}.gem,{artifactId}-{version}.gem.sha1,
* {artifactId}-{version}.pom,{artifactId}-{version}.pom.sha1]
*/
@Override
public RubygemsFile on(State state) {
Matcher m = FILE.matcher(state.name);
if (m.matches()) {
switch (m.group(1)) {
case "gem":
return state.context.factory.gemArtifact(artifactId, version);
case "pom":
return state.context.factory.pom(artifactId, version);
case "gem.sha1":
RubygemsFile file = state.context.factory.gemArtifact(artifactId, version);
return state.context.factory.sha1(file);
case "pom.sha1":
file = state.context.factory.pom(artifactId, version);
return state.context.factory.sha1(file);
default:
}
}
switch (state.name) {
case "":
return state.context.factory.gemArtifactIdVersionDirectory(state.context.original, artifactId, version, false);
default:
return state.context.factory.notFound(state.context.original);
}
}
} MavenReleasesRubygemsCuba.java 0000664 0000000 0000000 00000002661 14467014544 0040042 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /maven/releases/rubygems/
*
* @author christian
*/
public class MavenReleasesRubygemsCuba
implements Cuba {
/**
* directories one for each gem (name without version)
*/
@Override
public RubygemsFile on(State state) {
if (state.name.isEmpty()) {
return state.context.factory.rubygemsDirectory(state.context.original);
}
return state.nested(new MavenReleasesRubygemsArtifactIdCuba(state.name));
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/quick/ 0000775 0000000 0000000 00000000000 14467014544 0032214 5 ustar 00root root 0000000 0000000 QuickCuba.java 0000664 0000000 0000000 00000003264 14467014544 0034654 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/quick /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.quick;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /quick/
*
* @author christian
*/
public class QuickCuba
implements Cuba {
public static final String MARSHAL_4_8 = "Marshal.4.8";
private final Cuba quickMarshal;
public QuickCuba(Cuba cuba) {
this.quickMarshal = cuba;
}
/**
* directory [Marshal.4.8]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case MARSHAL_4_8:
return state.nested(quickMarshal);
case "":
return state.context.factory.directory(state.context.original,
MARSHAL_4_8);
default:
return state.context.factory.notFound(state.context.original);
}
}
} QuickMarshalCuba.java 0000664 0000000 0000000 00000004370 14467014544 0036163 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/quick /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.quick;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* cuba for /quick/Marshal.4.8
*
* @author christian
*/
public class QuickMarshalCuba
implements Cuba {
public static final String GEMSPEC_RZ = ".gemspec.rz";
private static Pattern FILE = Pattern.compile("^([^/]/)?([^/]+)" + GEMSPEC_RZ + "$");
/**
* no sub-directories
*
* create
* the directory itself does not produce the directory listing - only the empty
* and disallows
* after adding all the data, you can retrieve the list of gemnames for which
* there are dependency data and retrieve them as marshalled stream (same format as
*
* note: to restrict deleting to gem file is more precaution then a necessity.
*
* all other paths are forbidden.
*
* when uploading a gem all the specs.4.8 files will be updated.
*
* the dependency file for the gemname and gemspec file will be generated on
* demand.
*
* @author christian
* @see HostedGETLayout
*/
public class HostedPOSTLayout extends NoopDefaultLayout {
public HostedPOSTLayout(RubygemsGateway gateway, Storage store) {
super(gateway, store);
}
@Override
public void addGem(InputStream in, RubygemsFile file) {
if (file.type() != FileType.GEM && file.type() != FileType.API_V1) {
throw new RuntimeException("BUG: not allowed to store " + file);
}
try {
store.create(in, file);
if (file.hasNoPayload()) {
// an error or something else but we need the payload now
return;
}
GemspecHelper spec;
try (InputStream is = store.getInputStream(file)) {
spec = gateway.newGemspecHelperFromGem(is);
}
// check gemname matches coordinates from its specification
switch (file.type()) {
case GEM:
if (!(((GemFile) file).filename() + ".gem").equals(spec.filename())) {
store.delete(file);
// now set the error for further processing
file.setException(new IOException("filename " + file.name() + " does not match gemname: " + spec.filename()));
return;
}
break;
case API_V1:
try (InputStream is = store.getInputStream(file)) {
store.create(is, ((ApiV1File) file).gem(spec.filename()));
}
store.delete(file);
break;
default:
throw new RuntimeException("BUG");
}
addSpecToIndex(spec.gemspec());
// delete dependencies so the next request will recreate it
delete(super.dependencyFile(spec.name()));
// delete gemspec so the next request will recreate it
delete(super.gemspecFile(spec.filename().replaceFirst(".gem$", "")));
} catch (IOException e) {
file.setException(e);
}
}
/**
* add a spec (Ruby Object) to the specs.4.8 indices.
*/
private void addSpecToIndex(IRubyObject spec) throws IOException {
SpecsHelper specs = gateway.newSpecsHelper();
for (SpecsIndexType type : SpecsIndexType.values()) {
SpecsIndexZippedFile specsIndex = ensureSpecsIndexZippedFile(type);
ByteArrayInputStream gzippedResult = null;
try (InputStream in = new GZIPInputStream(store.getInputStream(specsIndex))) {
try (InputStream result = specs.addSpec(spec, in, type)) {
// if nothing was added the content is NULL
if (result != null) {
gzippedResult = IOUtil.toGzipped(result);
}
}
}
if (gzippedResult != null) {
store.update(gzippedResult, specsIndex);
}
}
}
@Override
public ApiV1File apiV1File(String name) {
ApiV1File apiV1 = super.apiV1File(name);
if (!"api_key".equals(apiV1.name())) {
apiV1.markAsForbidden();
}
return apiV1;
}
@Override
public SpecsIndexFile specsIndexFile(SpecsIndexType type) {
SpecsIndexFile file = super.specsIndexFile(type);
file.markAsForbidden();
return file;
}
@Override
public SpecsIndexZippedFile specsIndexZippedFile(SpecsIndexType type) {
SpecsIndexZippedFile file = super.specsIndexZippedFile(type);
file.markAsForbidden();
return file;
}
@Override
public SpecsIndexFile specsIndexFile(String name) {
SpecsIndexFile file = super.specsIndexFile(name);
file.markAsForbidden();
return file;
}
@Override
public SpecsIndexZippedFile specsIndexZippedFile(String name) {
SpecsIndexZippedFile file = super.specsIndexZippedFile(name);
file.markAsForbidden();
return file;
}
@Override
public GemspecFile gemspecFile(String name, String version, String platform) {
GemspecFile file = super.gemspecFile(name, version, platform);
file.markAsForbidden();
return file;
}
@Override
public GemspecFile gemspecFile(String name) {
GemspecFile file = super.gemspecFile(name);
file.markAsForbidden();
return file;
}
@Override
@Deprecated
public DependencyFile dependencyFile(String name) {
DependencyFile file = super.dependencyFile(name);
file.markAsForbidden();
return file;
}
@Override
public ApiV2File rubygemsInfoV2(String name, String version) {
ApiV2File file = super.rubygemsInfoV2(name, version);
file.markAsForbidden();
return file;
}
@Override
public CompactInfoFile compactInfo(String name) {
CompactInfoFile file = super.compactInfo(name);
file.markAsForbidden();
return file;
}
}
HostedRubygemsFileSystem.java 0000664 0000000 0000000 00000002617 14467014544 0037246 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.RubygemsGateway;
import org.torquebox.mojo.rubygems.cuba.DefaultRubygemsFileSystem;
/**
* this class assembles the hosted repository for GET, POST and DELETE request.
*
* @author christian
*/
public class HostedRubygemsFileSystem
extends DefaultRubygemsFileSystem {
public HostedRubygemsFileSystem(RubygemsGateway gateway, Storage store) {
super(new DefaultLayout(),
new HostedGETLayout(gateway, store),
new HostedPOSTLayout(gateway, store),
new HostedDELETELayout(gateway, store));
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/Layout.java 0000664 0000000 0000000 00000002642 14467014544 0033627 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.RubygemsFileFactory;
import java.io.InputStream;
/**
* it adds a single extra method to the
* it adds a few helper methods for sub classes.
*
* @author christian
*/
public class NoopDefaultLayout
extends DefaultLayout {
protected final RubygemsGateway gateway;
protected final Storage store;
public NoopDefaultLayout(RubygemsGateway gateway, Storage store) {
this.gateway = gateway;
this.store = store;
}
// all those files are generated on the fly
@Override
public Sha1File sha1(RubygemsFile file) {
Sha1File sha = super.sha1(file);
sha.markAsForbidden();
return sha;
}
@Override
public PomFile pomSnapshot(String name, String version, String timestamp) {
PomFile file = super.pomSnapshot(name, version, timestamp);
file.markAsForbidden();
return file;
}
@Override
public GemArtifactFile gemArtifactSnapshot(String name, String version, String timestamp) {
GemArtifactFile file = super.gemArtifactSnapshot(name, version, timestamp);
file.markAsForbidden();
return file;
}
@Override
public PomFile pom(String name, String version) {
PomFile file = super.pom(name, version);
file.markAsForbidden();
return file;
}
@Override
public GemArtifactFile gemArtifact(String name, String version) {
GemArtifactFile file = super.gemArtifact(name, version);
file.markAsForbidden();
return file;
}
@Override
public MavenMetadataSnapshotFile mavenMetadataSnapshot(String name, String version) {
MavenMetadataSnapshotFile file = super.mavenMetadataSnapshot(name, version);
file.markAsForbidden();
return file;
}
@Override
public MavenMetadataFile mavenMetadata(String name, boolean prereleased) {
MavenMetadataFile file = super.mavenMetadata(name, prereleased);
file.markAsForbidden();
return file;
}
@Override
public Directory directory(String path, String... items) {
Directory file = super.directory(path, items);
file.markAsForbidden();
return file;
}
@Override
public BundlerApiFile bundlerApiFile(String names) {
BundlerApiFile file = super.bundlerApiFile(names);
file.markAsForbidden();
return file;
}
/**
* on an empty storage there are no specs.4.8.gz, latest_specs.4.8.gz or prereleased_specs.4.8.gz
* files. this method will create fresh and empty such files (having an empty index).
*/
protected SpecsIndexZippedFile ensureSpecsIndexZippedFile(SpecsIndexType type) throws IOException {
SpecsIndexZippedFile specs = super.specsIndexZippedFile(type);
store.retrieve(specs);
if (specs.notExists()) {
try (InputStream content = gateway.newSpecsHelper().createEmptySpecs()) {
store.create(IOUtil.toGzipped(content), specs);
if (specs.hasNoPayload()) {
store.retrieve(specs);
}
if (specs.hasException()) {
throw new IOException(specs.getException());
}
}
}
return specs;
}
/**
* delete underlying file from storage.
*/
protected void delete(RubygemsFile file) throws IOException {
store.delete(file);
if (file.hasException()) {
throw new IOException(file.getException());
}
}
}
ProxiedGETLayout.java 0000664 0000000 0000000 00000012745 14467014544 0035450 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.ApiV2File;
import org.torquebox.mojo.rubygems.BundlerApiFile;
import org.torquebox.mojo.rubygems.DependencyFile;
import org.torquebox.mojo.rubygems.DependencyHelper;
import org.torquebox.mojo.rubygems.GemFile;
import org.torquebox.mojo.rubygems.GemspecFile;
import org.torquebox.mojo.rubygems.GemspecHelper;
import org.torquebox.mojo.rubygems.CompactInfoFile;
import org.torquebox.mojo.rubygems.RubygemsGateway;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
public class ProxiedGETLayout
extends GETLayout {
private final ProxyStorage store;
public ProxiedGETLayout(RubygemsGateway gateway, ProxyStorage store) {
super(gateway, store);
this.store = store;
}
private void maybeCreate(GemspecFile gemspec) {
if (gemspec.notExists() || gemspec.hasException()) {
Exception exp = gemspec.getException();
GemFile gem = gemspec.gem();
store.retrieve(gem);
if (gem.exists()) {
try {
GemspecHelper helper = gateway.newGemspecHelperFromGem(store.getInputStream(gem));
store.update(helper.getRzInputStream(), gemspec);
store.expireNow(gemspec);
} catch (IOException e) {
// in this case we stick to the original error of the gemspec file
if (exp != null) {
gemspec.setException(exp);
}
}
}
}
}
@Override
public GemspecFile gemspecFile(String name, String version, String platform) {
GemspecFile gemspec = super.gemspecFile(name, version, platform);
maybeCreate(gemspec);
return gemspec;
}
@Override
public GemspecFile gemspecFile(String filename) {
GemspecFile gemspec = super.gemspecFile(filename);
maybeCreate(gemspec);
return gemspec;
}
@Override
@Deprecated
public DependencyFile dependencyFile(String name) {
DependencyFile file = super.dependencyFile(name);
store.retrieve(file);
return file;
}
@Override
public ApiV2File rubygemsInfoV2(String name, String version) {
ApiV2File file = super.rubygemsInfoV2(name, version);
store.retrieve(file);
return file;
}
@Override
public CompactInfoFile compactInfo(String name) {
CompactInfoFile file = super.compactInfo(name);
store.retrieve(file);
return file;
}
@Override
protected void retrieveAll(BundlerApiFile file, DependencyHelper deps) throws IOException {
List
* note: dependency files are volatile can be cached only for a short periods
* (when they come from https://rubygems.org).
*/
boolean isExpired(DependencyFile file);
boolean isExpired(CompactInfoFile file);
/**
* expire the given file now, i.e. set the last modified timestamp to 0
*/
void expireNow(RubygemsFile file);
}
SimpleStorage.java 0000664 0000000 0000000 00000020641 14467014544 0035050 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.apache.commons.codec.binary.Base64;
import org.torquebox.mojo.rubygems.CompactInfoFile;
import org.torquebox.mojo.rubygems.DependencyFile;
import org.torquebox.mojo.rubygems.Directory;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.SpecsIndexFile;
import org.torquebox.mojo.rubygems.SpecsIndexZippedFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.security.SecureRandom;
import java.util.zip.GZIPInputStream;
/**
* simple storage implementation using the system's filesystem.
* it uses
* for GroupRepositories the DependencyFile
of the given gem
*/
public CompactInfoFile dependency() {
return this.factory.compactInfo(name());
}
/**
* setup the directory items. for each version one item, either
* released or prereleased version.
*/
public void setItems(DependencyData data) {
if (!prereleased) {
// we list ALL versions when not on prereleased directory
this.items.addAll(0, Arrays.asList(data.versions(false)));
}
this.items.addAll(0, Arrays.asList(data.versions(true)));
}
} GemArtifactIdVersionDirectory.java 0000664 0000000 0000000 00000003321 14467014544 0036647 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* represent /maven/releases/rubygems/{artifactId}/{version} or /maven/prereleases/rubygems/{artifactId}/{version}
*
* @author christian
*/
public class GemArtifactIdVersionDirectory
extends Directory {
/**
* setup the directory items
*/
GemArtifactIdVersionDirectory(RubygemsFileFactory factory,
String path,
String name,
String version,
boolean prerelease) {
super(factory, path, name);
String base = name + "-" + version + ".";
this.items.add(base + "pom");
this.items.add(base + "pom.sha1");
this.items.add(base + "gem");
this.items.add(base + "gem.sha1");
if (prerelease) {
this.items.add("maven-metadata.xml");
this.items.add("maven-metadata.xml.sha1");
}
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/GemFile.java 0000664 0000000 0000000 00000003443 14467014544 0032345 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* represents /gems/{name}-{version}.gem or /gems/{name}-{platform}-{version}.gem or /gems/{filename}.gem
*
* @author christian
*/
public class GemFile
extends BaseGemFile {
/**
* setup with full filename
*/
GemFile(RubygemsFileFactory factory, String storage, String remote, String filename) {
super(factory, FileType.GEM, storage, remote, filename);
}
/**
* setup with name, version and platform
*/
GemFile(RubygemsFileFactory factory,
String storage,
String remote,
String name,
String version,
String platform) {
super(factory, FileType.GEM, storage, remote, name, version, platform);
}
/**
* retrieve the associated gemspec
*/
public GemspecFile gemspec() {
if (version() != null) {
return factory.gemspecFile(name(), version(), platform());
} else {
return factory.gemspecFile(filename());
}
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/GemRunner.java 0000664 0000000 0000000 00000007615 14467014544 0032744 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
import org.jruby.runtime.builtin.IRubyObject;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GemRunner
extends ScriptWrapper {
private final String baseUrl;
public GemRunner(ScriptingContainer ruby, String baseUrl) {
super(ruby, newScript(ruby));
this.baseUrl = baseUrl;
}
private static Object newScript(final ScriptingContainer scriptingContainer) {
IRubyObject runnerClass = scriptingContainer.parse(PathType.CLASSPATH, "nexus/gem_runner.rb").run();
return scriptingContainer.callMethod(runnerClass, "new", IRubyObject.class);
}
public String install(String repoId, String... gems) {
ListInputStream
to an OutputStream
.
*/
public static void copy(final InputStream input, final OutputStream output) throws IOException {
final byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
}
public static ByteArrayInputStream toGzipped(final InputStream input) throws IOException {
ByteArrayOutputStream gzipped = new ByteArrayOutputStream();
try (GZIPOutputStream out = new GZIPOutputStream(gzipped)) {
copy(input, out);
}
return new ByteArrayInputStream(gzipped.toByteArray());
}
public static ByteArrayInputStream toGunzipped(final InputStream input) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(new GZIPInputStream(input), out);
return new ByteArrayInputStream(out.toByteArray());
}
}
MavenMetadataFile.java 0000664 0000000 0000000 00000003044 14467014544 0034262 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* represents /maven/releases/rubygems/{name}/maven-metadata.xml or /maven/prereleases/rubygems/{name}/maven-metadata.xml
*
* @author christian
*/
public class MavenMetadataFile
extends RubygemsFile {
private final boolean prereleased;
MavenMetadataFile(RubygemsFileFactory factory, String path, String name, boolean prereleased) {
super(factory, FileType.MAVEN_METADATA, path, path, name);
this.prereleased = prereleased;
}
/**
* whether it is a prerelease or not
*/
public boolean isPrerelease() {
return prereleased;
}
/**
* retrieve the associated DependencyFile
*/
public CompactInfoFile dependency() {
return factory.compactInfo(name());
}
} MavenMetadataSnapshotFile.java 0000664 0000000 0000000 00000002761 14467014544 0036007 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
/**
* represents /maven/prereleases/rubygems/{name}/{version}-SNAPSHOT/maven-metadata.xml
*
* @author christian
*/
public class MavenMetadataSnapshotFile
extends RubygemsFile {
private final String version;
MavenMetadataSnapshotFile(RubygemsFileFactory factory, String path, String name, String version) {
super(factory, FileType.MAVEN_METADATA_SNAPSHOT, path, path, name);
this.version = version;
}
/**
* version of the gem
*/
public String version() {
return version;
}
/**
* retrieve the associated DependencyFile
*/
public DependencyFile dependency() {
return factory.dependencyFile(name());
}
} MergeSpecsHelper.java 0000664 0000000 0000000 00000002542 14467014544 0034152 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
* helper to merge several specs-index files into one
*
* @author christian
*/
public interface MergeSpecsHelper {
/**
* add the specs data to the MergeSpecsHelper object
*
* @param specsData as InputStream
*/
void add(InputStream specsData);
/**
* marshal ruby object with
*
* @param latest whether of not
* @return ByteArrayInputStream of binary data
*/
ByteArrayInputStream getInputStream(boolean latest);
} MetadataBuilder.java 0000664 0000000 0000000 00000004172 14467014544 0034005 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
public class MetadataBuilder
extends AbstractMetadataBuilder {
private final StringBuilder xml;
private final DependencyData deps;
private boolean closed = false;
public MetadataBuilder(DependencyData deps) {
super(deps.modified());
this.deps = deps;
xml = new StringBuilder();
xml.append("RubygemsFile
*
* @author christian
*/
public interface RubygemsFileFactory {
/**
* create Directory
with given entries
*
* @return Directory
*/
Directory directory(String path, String... entries);
/**
* create RubygemsDirectory
/maven/releases/rubygems or /maven/prerelease/rubygems
*
* @return RubygemsDirectory
*/
RubygemsDirectory rubygemsDirectory(String path);
/**
* create Directory
/maven/releases/rubygems/{artifactId} or /maven/prerelease/rubygems/{artifactId}
*
* @param prereleases flag to create released or prereleased gem, i.e. without or with SNAPSHOT in version
* @return RubygemsDirectory
*/
Directory gemArtifactIdDirectory(String path, String artifactId, boolean prereleases);
/**
* create Directory
/maven/releases/rubygems/{artifactId}/{version} or
* /maven/prerelease/rubygems/{artifactId}/{version}
*
* @return RubygemsDirectory
*/
Directory gemArtifactIdVersionDirectory(String path, String artifactId, String version, boolean prereleases);
/**
* create GemFile
/gems/{name}-{version}.gem or /gems/{name}-{version}-{platform}.gem
*
* @param platform can be null
* @return GemFile
*/
GemFile gemFile(String name, String version, String platform);
/**
* create GemFile
/gems/{filename}.gem
*
* @return GemFile
*/
GemFile gemFile(String filename);
/**
* create GemspecFile
/quick/Marshal.4.8/{name}-{version}.gemspec.rz or
* /quick/Marshal.4.8/{name}-{version}-{platform}.gemspec.rz
*
* @param platform can be null
* @return GemspecFile
*/
GemspecFile gemspecFile(String name, String version, String platform);
/**
* create GemspecFile
/quick/Marshal.4.8/{filename}.gemspec.rz
*
* @return GemspecFile
*/
GemspecFile gemspecFile(String filename);
/**
* create DependencyFile
/api/v1/dependencies/{name}.ruby for
* a given gem-name
*
* @param name of the gemfile
* @return DependencyFile
*/
@Deprecated
DependencyFile dependencyFile(String name);
ApiV2File rubygemsInfoV2(String name, String version);
CompactInfoFile compactInfo(String name);
/**
* create BundlerApiFile
/api/v1/dependencies?gems=name1,name2,etc
*
* @param namesCommaSeparated which is a list of gem-names separated with a comma
* @return BundlerApiFile
*/
BundlerApiFile bundlerApiFile(String namesCommaSeparated);
/**
* create BundlerApiFile
/api/v1/dependencies?gems=name1,name2,etc
*
* @param names list of gem-names
* @return BundlerApiFile
*/
BundlerApiFile bundlerApiFile(String... names);
/**
* create ApiV1File
/api/v1/gem or /api/v1/api_key
*
* @param name which is either 'gem' or 'api_key'
* @return ApiV1File
*/
ApiV1File apiV1File(String name);
/**
* create SpecsIndexFile
/specs.4.8 or /latest_specs.4.8 or /prerelease_specs.4.8
*
* @param name which is either 'specs' or 'latest_specs' or 'prerelease_specs'
* @return SpecsIndexFile
*/
SpecsIndexFile specsIndexFile(String name);
/**
* create SpecsIndexFile
/specs.4.8 or /latest_specs.4.8 or /prerelease_specs.4.8
*/
SpecsIndexFile specsIndexFile(SpecsIndexType type);
/**
* create SpecsIndexZippedFile
/specs.4.8.gz or /latest_specs.4.8.gz or /prerelease_specs.4.8.gz
*
* @param name which is either 'specs' or 'latest_specs' or 'prerelease_specs'
*/
SpecsIndexZippedFile specsIndexZippedFile(String name);
/**
* create SpecsIndexZippedFile
/specs.4.8 or /latest_specs.4.8 or /prerelease_specs.4.8
*/
SpecsIndexZippedFile specsIndexZippedFile(SpecsIndexType type);
/**
* create MavenMetadataFile
/maven/releases/rubygems/{name}/maven-metadata.xml or
* /maven/prereleases/rubygems/{name}/maven-metadata.xml
*
* @param name gem name
* @param prereleased a flag whether to add '-SNAPSHOT' to version or not
* @return MavenMetadataFile
*/
MavenMetadataFile mavenMetadata(String name, boolean prereleased);
/**
* create MavenMetadataSnapshotFile
/maven/prereleases/rubygems/{name}/{version}/maven-metadata.xml
*
* @param name gem name
* @param version of the gem
* @return MavenMetadataSnapshotFile
*/
MavenMetadataSnapshotFile mavenMetadataSnapshot(String name, String version);
/**
* create PomFile
/maven/prereleases/rubygems/{name}/{version}/{name}-{version}-SNAPSHOT.pom
*
* @param name gem name
* @param version of the gem
* @param timestamp when the gem was created
* @return PomFile
*/
PomFile pomSnapshot(String name, String version, String timestamp);
/**
* create PomFile
/maven/releases/rubygems/{name}/{version}/{name}-{version}.pom
*
* @param name gem name
* @param version of the gem
* @return PomFile
*/
PomFile pom(String name, String version);
/**
* create PomFile
/maven/prereleases/rubygems/{name}/{version}/{name}-{version}-SNAPSHOT.gem
*
* @param name gem name
* @param version of the gem
* @param timestamp when the gem was created
* @return PomFile
*/
GemArtifactFile gemArtifactSnapshot(String name, String version, String timestamp);
/**
* create PomFile
/maven/releases/rubygems/{name}/{version}/{name}-{version}.gem
*
* @param name gem name
* @param version of the gem
* @return PomFile
*/
GemArtifactFile gemArtifact(String name, String version);
/**
* create NotFoundFile
for any path name not belonging to the rubygems world
*
* @return NotFoundFile
*/
NotFoundFile notFound(String path);
/**
* create Sha1File
for a given RubygemsFile
*
* @param file the sha1 is for this RubygemsFile
* @return Sha1File
*/
Sha1File sha1(RubygemsFile file);
/**
* Create a NoContentFile
for /api/v1/dependencies and /api/v1/dependencies?gems=
*
* @param path for this RubygemsFile
* @return NoContentFile
*/
NoContentFile noContent(String path);
} RubygemsGateway.java 0000664 0000000 0000000 00000007421 14467014544 0034075 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import java.io.InputStream;
/**
* factory for all the ruby classes. all those ruby classes come with java interface
* so they can be used easily from java.
*
* @author christian
*/
public interface RubygemsGateway {
/**
* Cleans up resources used by gateway and terminates it along with the underlying scripting container.
*/
void terminate();
/**
* create a new instance of GemspecHelper
*
* @param gemspec the stream to the rzipped marshalled Gem::Specification ruby-object
* @return an empty GemspecHelper
*/
GemspecHelper newGemspecHelper(InputStream gemspec);
/**
* create a new instance of GemspecHelper
*
* @param gem the stream to the from which the gemspec gets extracted
* @return an empty GemspecHelper
*/
GemspecHelper newGemspecHelperFromGem(InputStream gem);
/**
* create a new instance of GemspecHelper
*
* @param v2GemInfo the stream to the v2 API gem info
* @return an empty GemspecHelper
*/
GemspecHelper newGemspecHelperFromV2GemInfo(InputStream v2GemInfo);
/**
* create a new instance of DependencyHelper
*
* @return an empty DependencyHelper
*/
DependencyHelper newDependencyHelper();
/**
* create a new instance of SpecsHelper
*
* @return an empty SpecsHelper
*/
SpecsHelper newSpecsHelper();
/**
* create a new instance of MergeSpecsHelper
*
* @return an empty MergeSpecsHelper
*/
MergeSpecsHelper newMergeSpecsHelper();
/**
* create a new instance of DependencyData
and parse
* the given dependency data
*
* @param dependency the input-stream with the dependency data
* @param name of gem of the dependency data
* @param modified when the dependency data were last modified
* @return dependency data
*/
DependencyData newDependencyData(InputStream dependency, String name, long modified);
/**
* create a new instance of RubygemsV2GemInfo
and parse
* the given v2 API endpoint
*
* @param dependency the input-stream with the gem info data
* @param name of gem of the gem info data
* @param version of gem of the gem info data
* @param modified when the gem info data were last modified
* @return gem info data
*/
RubygemsV2GemInfo newRubygemsV2GemInfo(InputStream dependency, String name, String version, long modified);
/**
* create a new instance of DependencyData
and parse
* the given compact dependency data
*
* @param dependency the input-stream with the dependency data
* @param name of gem of the dependency data
* @param modified when the dependency data were last modified
* @return dependency data
*/
DependencyData newCompactDependencyData(InputStream dependency, String name, long modified);
}
RubygemsV2GemInfo.java 0000664 0000000 0000000 00000000276 14467014544 0034231 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems package org.torquebox.mojo.rubygems;
public interface RubygemsV2GemInfo {
public String version();
public String platform();
public String name();
public long modified();
}
mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/ScriptWrapper.java 0000664 0000000 0000000 00000003641 14467014544 0033642 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import org.jruby.embed.ScriptingContainer;
public abstract class ScriptWrapper {
protected final ScriptingContainer scriptingContainer;
private final Object object;
public ScriptWrapper(ScriptingContainer scriptingContainer, Object object) {
this.scriptingContainer = scriptingContainer;
this.object = object;
}
protected void callMethod(String methodName, Object singleArg) {
scriptingContainer.callMethod(object, methodName, singleArg);
}
protected RubygemsFile
*
* @author christian
*/
public class Sha1File
extends RubygemsFile {
private final RubygemsFile source;
Sha1File(RubygemsFileFactory factory, String storage, String remote, RubygemsFile source) {
super(factory, FileType.SHA1, storage, remote, source.name());
this.source = source;
if (source.notExists()) {
markAsNotExists();
}
}
/**
* the source for which the SHA1 digest
*
* @return RubygemsFile
*/
public RubygemsFile getSource() {
return source;
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/SpecsHelper.java 0000664 0000000 0000000 00000010073 14467014544 0033247 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems;
import org.jruby.runtime.builtin.IRubyObject;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
/**
* helper around specs index like adding a spec to the index or deleting a spec from the index.
* since spec index is marshal ruby object it offers a method to get the data for an empty spec index.
* when to create a DependencyFile
you need to interate over all versions of a given gem.
*
* @author christian
*/
public interface SpecsHelper {
/**
* create an emptry spec index, i.e. create marshaled ruby object for an empty spec index
*
* @return the stream to data
*/
ByteArrayInputStream createEmptySpecs();
/**
* adds the given spec to the spec index. the action depends on the SpecsIndexTyep
:
*
* it only returns the new specs index if it changes, i.e. if the given spec already exists in the specs index
* then a null
gets returned.
*
* @param spec a Gem::Specification ruby object
* @param specsIndex the InputStream
to the spec index
* @param type whether it is release, prerelease or latest
* @return the next spec index as ByteArrayInputStream
if there was a change or null
* if the spec index remained the same
*/
ByteArrayInputStream addSpec(IRubyObject spec, InputStream specsIndex, SpecsIndexType type);
/**
* it deletes the given spec from the spec index. if spec does not exist
*
* null
gets returned.
* InputStream
to the spec index
* @param type whether it is release, prerelease or latest
* @return the next spec index as ByteArrayInputStream
*/
ByteArrayInputStream deleteSpec(IRubyObject spec, InputStream specsIndex, SpecsIndexType type);
/**
* collect all versions from the given specs index for given gemname.
*
* @param gemname for which the version list shall be retrieved
* @param specsIndex InputStream
to specs index
* @return
*/
ListContext
carries the original path and the query string
* from the (HTTP) request as well the RubygemsFileFactory
which
* is used by the Cuba
objects to create RubygemsFile
s.
* State
object and is immutable.
*
* @author christian
*/
public class Context {
public final String original;
public final String query;
public final RubygemsFileFactory factory;
public Context(RubygemsFileFactory factory, String original, String query) {
this.original = original;
this.query = query;
this.factory = factory;
}
public String toString() {
StringBuilder b = new StringBuilder(getClass().getSimpleName());
b.append("<").append(original);
if (!query.isEmpty()) {
b.append("?").append(query);
}
b.append(">");
return b.toString();
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/Cuba.java 0000664 0000000 0000000 00000002027 14467014544 0032616 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba;
import org.torquebox.mojo.rubygems.RubygemsFile;
public interface Cuba {
/**
* create the RubygemsFile for the given State
*
* @return RubygemsFile
*/
RubygemsFile on(State state);
} DefaultRubygemsFileSystem.java 0000664 0000000 0000000 00000006143 14467014544 0036777 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba;
import org.torquebox.mojo.rubygems.RubygemsFileFactory;
import org.torquebox.mojo.rubygems.cuba.api.ApiCuba;
import org.torquebox.mojo.rubygems.cuba.api.ApiV1Cuba;
import org.torquebox.mojo.rubygems.cuba.api.ApiV1DependenciesCuba;
import org.torquebox.mojo.rubygems.cuba.api.ApiV2Cuba;
import org.torquebox.mojo.rubygems.cuba.api.ApiV2RubygemsCuba;
import org.torquebox.mojo.rubygems.cuba.api.CompactInfoCuba;
import org.torquebox.mojo.rubygems.cuba.gems.GemsCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenPrereleasesCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenPrereleasesRubygemsCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenReleasesCuba;
import org.torquebox.mojo.rubygems.cuba.maven.MavenReleasesRubygemsCuba;
import org.torquebox.mojo.rubygems.cuba.quick.QuickCuba;
import org.torquebox.mojo.rubygems.cuba.quick.QuickMarshalCuba;
import org.torquebox.mojo.rubygems.layout.DefaultLayout;
import org.torquebox.mojo.rubygems.layout.Layout;
public class DefaultRubygemsFileSystem extends RubygemsFileSystem {
public DefaultRubygemsFileSystem(RubygemsFileFactory fileLayout, Layout getLayout, Layout postLayout, Layout deleteLayout) {
super(fileLayout, getLayout, postLayout, deleteLayout,
// TODO move to javax.inject
new RootCuba(
new ApiCuba(
new ApiV1Cuba(new ApiV1DependenciesCuba()),
new ApiV2Cuba(new ApiV2RubygemsCuba()),
new QuickCuba(new QuickMarshalCuba()),
new GemsCuba()),
new QuickCuba(new QuickMarshalCuba()),
new GemsCuba(),
new MavenCuba(
new MavenReleasesCuba(new MavenReleasesRubygemsCuba()),
new MavenPrereleasesCuba(new MavenPrereleasesRubygemsCuba())),
new CompactInfoCuba()
));
}
public DefaultRubygemsFileSystem(Layout getLayout, Layout postLayout, Layout deleteLayout) {
this(new DefaultLayout(), getLayout, postLayout, deleteLayout);
}
public DefaultRubygemsFileSystem() {
this(new DefaultLayout(), null, null, null);
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/RootCuba.java 0000664 0000000 0000000 00000006035 14467014544 0033465 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba;
import org.torquebox.mojo.rubygems.RubygemsFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* cuba for /
*
* @author christian
*/
public class RootCuba implements Cuba {
public static final String _4_8 = ".4.8";
public static final String GZ = ".gz";
public static final String API = "api";
public static final String QUICK = "quick";
public static final String GEMS = "gems";
public static final String MAVEN = "maven";
public static final String INFO = "info";
private static final Pattern SPECS = Pattern.compile("^((prerelease_|latest_)?specs)" + _4_8 + "(" + GZ + ")?$");
private final Cuba api;
private final Cuba quick;
private final Cuba gems;
private final Cuba maven;
private final Cuba info;
public RootCuba(Cuba api, Cuba quick, Cuba gems, Cuba maven, Cuba info) {
this.api = api;
this.quick = quick;
this.gems = gems;
this.maven = maven;
this.info = info;
}
/**
* directories [api, quick, gems, maven]
* State
with the current directory name
* and the not parsed path.
* Cuba
object to eval itself via the nested
* method.
*
* @author christian
*/
public class State {
static Pattern PATH_PART = Pattern.compile("^/([^/]*).*");
public final String path;
public final String name;
public final Context context;
public State(Context ctx, String path, String name) {
this.context = ctx;
this.path = path;
this.name = name;
}
/**
* it passes on the next directory of the remaining path (can be empty)
* or there is no next directory then a RubygemsFile
marked
* as notFound
is created.
*/
public RubygemsFile nested(Cuba cuba) {
if (path.isEmpty()) {
// that is an directory, let the cuba object create the
// right RubygemsFile for it
return cuba.on(new State(context, "", ""));
}
Matcher m = PATH_PART.matcher(path);
if (m.matches()) {
String name = m.group(1);
return cuba.on(new State(context,
this.path.substring(1 + name.length()),
name));
}
return context.factory.notFound(context.original);
}
public String toString() {
StringBuilder b = new StringBuilder(getClass().getSimpleName());
b.append("<").append(path).append(",").append(name).append("> )");
return b.toString();
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api/ 0000775 0000000 0000000 00000000000 14467014544 0031651 5 ustar 00root root 0000000 0000000 ApiCuba.java 0000664 0000000 0000000 00000004204 14467014544 0033741 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.RootCuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /api/
*
* @author christian
*/
public class ApiCuba implements Cuba {
public static final String V1 = "v1";
public static final String V2 = "v2";
private final Cuba v1;
private final Cuba v2;
private final Cuba quick;
private final Cuba gems;
public ApiCuba(Cuba v1, Cuba v2, Cuba quick, Cuba gems) {
this.v1 = v1;
this.v2 = v2;
this.quick = quick;
this.gems = gems;
}
/**
* directory [v1,quick]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case V1:
return state.nested(v1);
case V2:
return state.nested(v2);
case RootCuba.QUICK:
return state.nested(quick);
case RootCuba.GEMS:
return state.nested(gems);
case "":
String[] items = {V1, RootCuba.QUICK, RootCuba.GEMS};
return state.context.factory.directory(state.context.original, items);
default:
return state.context.factory.notFound(state.context.original);
}
}
} ApiV1Cuba.java 0000664 0000000 0000000 00000003645 14467014544 0034160 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /api/v1
*
* @author christian
*/
public class ApiV1Cuba
implements Cuba {
public static final String DEPENDENCIES = "dependencies";
private static final String GEMS = "gems";
private static final String API_KEY = "api_key";
private final Cuba apiV1Dependencies;
public ApiV1Cuba(Cuba cuba) {
this.apiV1Dependencies = cuba;
}
/**
* directory [dependencies], files [api_key,gems]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case DEPENDENCIES:
return state.nested(apiV1Dependencies);
case GEMS:
case API_KEY:
return state.context.factory.apiV1File(state.name);
case "":
return state.context.factory.directory(state.context.original, API_KEY, DEPENDENCIES);
default:
return state.context.factory.notFound(state.context.original);
}
}
} ApiV1DependenciesCuba.java 0000664 0000000 0000000 00000005720 14467014544 0036463 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* cuba for /api/v1/dependencies
*
* @author christian
*/
public class ApiV1DependenciesCuba
implements Cuba {
public static final String RUBY = ".ruby";
private static final Pattern FILE = Pattern.compile("^([^/]+)[.]" + RUBY.substring(1) + "$");
/**
* no sub-directories
* BundlerApiFile
or
* DependencyFile
gets created.
* DependencyFile
* Directory
* object.
*/
@Override
public RubygemsFile on(State state) {
if (state.name.isEmpty()) {
if (state.context.query.startsWith("gems=")) {
if (state.context.query.contains(",") || state.context.query.contains("%2C")) {
return state.context.factory.bundlerApiFile(state.context.query.substring(5));
} else if (state.context.query.length() > 5) {
return state.context.factory.compactInfo(state.context.query.substring(5));
}
}
if (state.context.original.endsWith("/")) {
return state.context.factory.directory(state.context.original);
} else {
return state.context.factory.noContent(state.context.original);
}
}
Matcher m;
if (state.name.length() == 1) {
if (state.path.length() < 2) {
return state.context.factory.directory(state.context.original);
}
m = FILE.matcher(state.path.substring(1));
} else {
m = FILE.matcher(state.name);
}
if (m.matches()) {
return state.context.factory.compactInfo(m.group(1));
}
return state.context.factory.notFound(state.context.original);
}
}
ApiV2Cuba.java 0000664 0000000 0000000 00000003073 14467014544 0034154 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /api/v2 to fetch gem details
*
* @author christian
*/
public class ApiV2Cuba
implements Cuba {
public static final String RUBYGEMS = "rubygems";
private final Cuba apiV2Rubygems;
public ApiV2Cuba(Cuba apiV2Rubygems) {
this.apiV2Rubygems = apiV2Rubygems;
}
/**
* directory [dependencies], files [api_key,gems]
*/
@Override
public RubygemsFile on(State state) {
if (state.name.equals(ApiV2Cuba.RUBYGEMS)) {
return state.nested(apiV2Rubygems);
}
return state.context.factory.notFound(state.context.original);
}
} ApiV2RubygemsCuba.java 0000664 0000000 0000000 00000002567 14467014544 0035701 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /api/v2/rubygems to fetch gem details
*/
public class ApiV2RubygemsCuba implements Cuba {
/**
* directory [dependencies], files [api_key,gems]
*/
@Override
public RubygemsFile on(State state) {
if (state.name.isEmpty()) {
return state.context.factory.notFound(state.context.original);
}
return state.nested(new ApiV2RubygemsNameCuba(state.name));
}
} ApiV2RubygemsNameCuba.java 0000664 0000000 0000000 00000003055 14467014544 0036473 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /api/v2/rubygems to fetch gem details
*/
public class ApiV2RubygemsNameCuba implements Cuba {
public static final String VERSIONS = "versions";
private final String name;
public ApiV2RubygemsNameCuba(String name) {
this.name = name;
}
/**
* directory [dependencies], files [api_key,gems]
*/
@Override
public RubygemsFile on(State state) {
if (state.name.equals(VERSIONS)) {
return state.nested(new ApiV2RubygemsNameVersionsCuba(name));
}
return state.context.factory.notFound(state.context.original);
}
} ApiV2RubygemsNameVersionsCuba.java 0000664 0000000 0000000 00000003300 14467014544 0040215 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /api/v2/rubygems/NAME/versions/VERSION
*/
public class ApiV2RubygemsNameVersionsCuba implements Cuba {
private final String name;
public ApiV2RubygemsNameVersionsCuba(String name) {
this.name = name;
}
/**
* directory [dependencies], files [api_key,gems]
*/
@Override
public RubygemsFile on(State state) {
if (state.name.isEmpty()) {
return state.context.factory.notFound(state.context.original);
}
String version = state.name;
int jsonExt = version.indexOf(".json");
if (jsonExt != -1) {
version = version.substring(0, jsonExt);
}
return state.nested(new ApiV2RubygemsNameVersionsNumberCuba(name, version));
}
} ApiV2RubygemsNameVersionsNumberCuba.java 0000664 0000000 0000000 00000002660 14467014544 0041376 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /api/v2/rubygems/GEM/versions/NUM
*
* @author christian
*/
public class ApiV2RubygemsNameVersionsNumberCuba implements Cuba {
private final String name;
private final String version;
public ApiV2RubygemsNameVersionsNumberCuba(String name, String version) {
this.name = name;
this.version = version;
}
@Override
public RubygemsFile on(State state) {
return state.context.factory.rubygemsInfoV2(name, version);
}
}
CompactInfoCuba.java 0000664 0000000 0000000 00000003076 14467014544 0035440 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/api /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.api;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /info/GEMNAME
*/
public class CompactInfoCuba implements Cuba {
public CompactInfoCuba() {
}
/**
* json listing of all versions of a given gem with dependencies
*/
@Override
public RubygemsFile on(State state) {
if (state.name != null) {
String baseName = state.name;
int ext = baseName.indexOf(".compact");
if (ext != -1) {
baseName = baseName.substring(0, ext);
}
return state.context.factory.compactInfo(baseName);
}
return state.context.factory.noContent(state.path);
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/gems/ 0000775 0000000 0000000 00000000000 14467014544 0032033 5 ustar 00root root 0000000 0000000 GemsCuba.java 0000664 0000000 0000000 00000004275 14467014544 0034315 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/gems /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.gems;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* cuba for /gems
*
* @author christian
*/
public class GemsCuba
implements Cuba {
public static final String GEM = ".gem";
private static final Pattern FILE = Pattern.compile("^([^/]/)?([^/]+)" + GEM + "$");
/**
* no sub-directories
* GemFile
s for {name}-{version}.gem or {first-char-of-name}/{name}-{version}.gem
* Directory
* object.
*/
@Override
public RubygemsFile on(State state) {
Matcher m;
if (state.name.length() == 1) {
if (state.path.length() < 2) {
return state.context.factory.directory(state.context.original);
}
m = FILE.matcher(state.path.substring(1));
} else {
m = FILE.matcher(state.name);
}
if (m.matches()) {
return state.context.factory.gemFile(m.group(2));
}
if (state.name.isEmpty()) {
return state.context.factory.directory(state.context.original);
}
return state.context.factory.notFound(state.context.original);
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven/ 0000775 0000000 0000000 00000000000 14467014544 0032206 5 ustar 00root root 0000000 0000000 MavenCuba.java 0000664 0000000 0000000 00000003647 14467014544 0034645 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /maven
*
* @author christian
*/
public class MavenCuba
implements Cuba {
public static final String RELEASES = "releases";
public static final String PRERELEASES = "prereleases";
private final Cuba releases;
private final Cuba prereleases;
public MavenCuba(Cuba releases, Cuba prereleases) {
this.releases = releases;
this.prereleases = prereleases;
}
/**
* directories [releases,prereleases]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case RELEASES:
return state.nested(releases);
case PRERELEASES:
return state.nested(prereleases);
case "":
return state.context.factory.directory(state.context.original,
PRERELEASES, RELEASES);
default:
return state.context.factory.notFound(state.context.original);
}
}
} MavenPrereleasesCuba.java 0000664 0000000 0000000 00000003273 14467014544 0037033 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /maven/prereleases/
*
* @author christian
*/
public class MavenPrereleasesCuba
implements Cuba {
private final Cuba mavenPrereleasesRubygems;
public MavenPrereleasesCuba(Cuba cuba) {
mavenPrereleasesRubygems = cuba;
}
/**
* directory [rubygems]
*/
@Override
public RubygemsFile on(State state) {
switch (state.name) {
case MavenReleasesCuba.RUBYGEMS:
return state.nested(mavenPrereleasesRubygems);
case "":
return state.context.factory.directory(state.context.original, MavenReleasesCuba.RUBYGEMS);
default:
return state.context.factory.notFound(state.context.original);
}
}
} MavenPrereleasesRubygemsArtifactIdCuba.java 0000664 0000000 0000000 00000004414 14467014544 0042502 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/cuba/maven /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.cuba.maven;
import org.torquebox.mojo.rubygems.MavenMetadataFile;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.cuba.Cuba;
import org.torquebox.mojo.rubygems.cuba.State;
/**
* cuba for /maven/prereleases/rubygems/{artifactId}
*
* @author christian
*/
public class MavenPrereleasesRubygemsArtifactIdCuba
implements Cuba {
public static final String SNAPSHOT = "-SNAPSHOT";
private final String name;
public MavenPrereleasesRubygemsArtifactIdCuba(String name) {
this.name = name;
}
/**
* directories one for each version of the gem with given name/artifactId
* GemspecFile
s for {name}-{version}.gemspec.rz or {first-char-of-name}/{name}-{version}.gemspec.rz
* Directory
* object.
*/
@Override
public RubygemsFile on(State state) {
Matcher m;
if (state.name.length() == 1) {
if (state.path.length() < 2) {
return state.context.factory.directory(state.context.original);
}
m = FILE.matcher(state.path.substring(1));
} else {
m = FILE.matcher(state.name);
}
if (m.matches()) {
return state.context.factory.gemspecFile(m.group(2));
}
if (state.name.isEmpty()) {
return state.context.factory.directory(state.context.original);
}
return state.context.factory.notFound(state.context.original);
}
} mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/ 0000775 0000000 0000000 00000000000 14467014544 0031503 5 ustar 00root root 0000000 0000000 CachingProxyStorage.java 0000664 0000000 0000000 00000014573 14467014544 0036224 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.BundlerApiFile;
import org.torquebox.mojo.rubygems.CompactInfoFile;
import org.torquebox.mojo.rubygems.DependencyFile;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.SpecsIndexZippedFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* it uses the SimpleStorage
to cache the remote files.
*
* @author christian
*/
public class CachingProxyStorage
extends SimpleStorage
implements ProxyStorage {
protected final String baseurl;
private final ConcurrentMap
*
* SpecsIndexZippedFile
GemFile
GemspecFile
DependencyFile
*
*
* @author christian
*/
public class DELETELayout extends NoopDefaultLayout {
public DELETELayout(RubygemsGateway gateway, Storage store) {
super(gateway, store);
}
@Override
public SpecsIndexFile specsIndexFile(String name) {
SpecsIndexFile file = super.specsIndexFile(name);
file.markAsForbidden();
return file;
}
@Override
public SpecsIndexZippedFile specsIndexZippedFile(String name) {
SpecsIndexZippedFile file = super.specsIndexZippedFile(name);
store.delete(file);
return file;
}
@Override
public ApiV1File apiV1File(String name) {
ApiV1File file = super.apiV1File(name);
file.markAsForbidden();
return file;
}
@Override
public GemFile gemFile(String name, String version, String platform) {
GemFile file = super.gemFile(name, version, platform);
store.delete(file);
return file;
}
@Override
public GemFile gemFile(String name) {
GemFile file = super.gemFile(name);
store.delete(file);
return file;
}
@Override
public GemspecFile gemspecFile(String name, String version, String platform) {
GemspecFile file = super.gemspecFile(name, version, platform);
store.delete(file);
return file;
}
@Override
public GemspecFile gemspecFile(String name) {
GemspecFile file = super.gemspecFile(name);
store.delete(file);
return file;
}
@Override
@Deprecated
public DependencyFile dependencyFile(String name) {
DependencyFile file = super.dependencyFile(name);
store.delete(file);
return file;
}
@Override
public ApiV2File rubygemsInfoV2(String name, String version) {
ApiV2File file = super.rubygemsInfoV2(name, version);
store.delete(file);
return file;
}
@Override
public CompactInfoFile compactInfo(String name) {
CompactInfoFile file = super.compactInfo(name);
store.delete(file);
return file;
}
}
DefaultLayout.java 0000664 0000000 0000000 00000002445 14467014544 0035056 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.DefaultRubygemsFileFactory;
import org.torquebox.mojo.rubygems.RubygemsFile;
import java.io.InputStream;
/**
* adds dummy implementation for {@link Layout#addGem(InputStream, RubygemsFile)}
*
* @author christian
*/
public class DefaultLayout
extends DefaultRubygemsFileFactory
implements Layout {
@Override
public void addGem(InputStream is, RubygemsFile file) {
throw new RuntimeException("not implemented !");
}
} DependencyHelper.java 0000664 0000000 0000000 00000005024 14467014544 0035506 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
* helper to collect or merge dependency data from SpecsIndexFile
ApiV1File
DependencyFile
s
* or extract the dependency data from a given GemspecFile
.
* the remote data from BundlerApiFile
is collection of the same
* dependency data format which can added as well.
* DependencyFile
or BundlerApiFile
).
*
* @author christian
*/
public interface DependencyHelper {
/**
* add dependency data to instance
*
* @param marshalledDependencyData stream of the marshalled "ruby" data
*/
void add(InputStream marshalledDependencyData);
/**
* add dependency data to instance from a rzipped gemspec object.
*
* @param gemspec rzipped stream of the marshalled gemspec object
*/
void addGemspec(InputStream gemspec);
/**
* freezes the instance - no more added of data is allowed - and returns
* the list of gemnames for which dependency data was added.
*
* @return String[] of gemnames
*/
String[] getGemnames();
/**
* marshal ruby object with dependency data for the given gemname.
*
* @param gemname
* @return ByteArrayInputStream of binary data
*/
ByteArrayInputStream getInputStreamOf(String gemname);
/**
* marshal ruby object with dependency data for all the dependency data,
* either with or without duplicates.
*
* @return ByteArrayInputStream of binary data
*/
ByteArrayInputStream getInputStream(boolean unique);
} GETLayout.java 0000664 0000000 0000000 00000027545 14467014544 0034121 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.ApiV1File;
import org.torquebox.mojo.rubygems.ApiV2File;
import org.torquebox.mojo.rubygems.BundlerApiFile;
import org.torquebox.mojo.rubygems.CompactInfoFile;
import org.torquebox.mojo.rubygems.DependencyData;
import org.torquebox.mojo.rubygems.DependencyFile;
import org.torquebox.mojo.rubygems.DependencyHelper;
import org.torquebox.mojo.rubygems.Directory;
import org.torquebox.mojo.rubygems.GemArtifactFile;
import org.torquebox.mojo.rubygems.GemArtifactIdDirectory;
import org.torquebox.mojo.rubygems.GemFile;
import org.torquebox.mojo.rubygems.GemspecFile;
import org.torquebox.mojo.rubygems.MavenMetadataFile;
import org.torquebox.mojo.rubygems.MavenMetadataSnapshotFile;
import org.torquebox.mojo.rubygems.MetadataBuilder;
import org.torquebox.mojo.rubygems.MetadataSnapshotBuilder;
import org.torquebox.mojo.rubygems.PomFile;
import org.torquebox.mojo.rubygems.RubygemsDirectory;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.RubygemsGateway;
import org.torquebox.mojo.rubygems.RubygemsV2GemInfo;
import org.torquebox.mojo.rubygems.Sha1Digest;
import org.torquebox.mojo.rubygems.Sha1File;
import org.torquebox.mojo.rubygems.SpecsIndexFile;
import org.torquebox.mojo.rubygems.SpecsIndexZippedFile;
import java.io.IOException;
import java.io.InputStream;
/**
* a base layout for HTTP GET requests.
*
*
*
*
* @author christian
*/
public class GETLayout
extends DefaultLayout
implements Layout {
protected final RubygemsGateway gateway;
protected final Storage store;
public GETLayout(RubygemsGateway gateway, Storage store) {
this.gateway = gateway;
this.store = store;
}
/**
* this allows sub-classes to add more functionality, like creating an
* empty SpecsIndexZippedFile.
*/
protected void retrieveZipped(SpecsIndexZippedFile specs) {
store.retrieve(specs);
}
@Override
public SpecsIndexFile specsIndexFile(String name) {
SpecsIndexFile specs = super.specsIndexFile(name);
// just make sure we have a zipped file, i.e. create an empty one
retrieveZipped(specs.zippedSpecsIndexFile());
// now retrieve the unzipped one
store.retrieve(specs);
return specs;
}
@Override
public SpecsIndexZippedFile specsIndexZippedFile(String name) {
SpecsIndexZippedFile specs = super.specsIndexZippedFile(name);
retrieveZipped(specs);
return specs;
}
/**
* subclasses can overwrite this, to collect the dependencies files differently. i.e.
* a proxy might want to load only the missing or expired dependency files.
*
* @param file with the list of gem-names
* @param deps the result set of GemArtifactFile
sDependencyFile
s and merge them for the BundlerApiFile
payloadSha1File
s and MavenMetadataFile
s on the flyInputStream
s to all the DependencyFile
of the
* given list of gem-names
*/
protected void retrieveAll(BundlerApiFile file, DependencyHelper deps) throws IOException {
for (String name : file.gemnames()) {
CompactInfoFile compactInfo = compactInfo(name);
try (InputStream is = store.getInputStream(compactInfo)) {
deps.addCompact(is, name, store.getModified(compactInfo));
}
}
}
@Override
public BundlerApiFile bundlerApiFile(String namesCommaSeparated) {
BundlerApiFile file = super.bundlerApiFile(namesCommaSeparated);
DependencyHelper deps = gateway.newDependencyHelper();
try {
retrieveAll(file, deps);
if (!file.hasException()) {
store.memory(deps.getInputStream(false), file);
}
} catch (IOException e) {
file.setException(e);
}
return file;
}
@Override
public RubygemsDirectory rubygemsDirectory(String path) {
RubygemsDirectory dir = super.rubygemsDirectory(path);
Directory d = directory("/api/v1/dependencies/");
dir.setItems(store.listDirectory(d));
// copy the error over to the original directory
if (d.hasException()) {
dir.setException(d.getException());
}
return dir;
}
@Override
public GemArtifactIdDirectory gemArtifactIdDirectory(String path, String name,
boolean prereleases) {
GemArtifactIdDirectory dir = super.gemArtifactIdDirectory(path, name, prereleases);
try {
dir.setItems(newDependencyData(dir.dependency()));
} catch (IOException e) {
dir.setException(e);
}
return dir;
}
@Override
public MavenMetadataFile mavenMetadata(String name, boolean prereleased) {
MavenMetadataFile file = super.mavenMetadata(name, prereleased);
try {
MetadataBuilder meta = new MetadataBuilder(newDependencyData(file.dependency()));
meta.appendVersions(file.isPrerelease());
store.memory(meta.toString(), file);
} catch (IOException e) {
file.setException(e);
}
return file;
}
@Override
public MavenMetadataSnapshotFile mavenMetadataSnapshot(String name, String version) {
MavenMetadataSnapshotFile file = super.mavenMetadataSnapshot(name, version);
MetadataSnapshotBuilder meta = new MetadataSnapshotBuilder(name, version, store.getModified(file.dependency()));
store.memory(meta.toString(), file);
return file;
}
/**
* generate the pom.xml and set it as payload to the given PomFile
*/
protected void setPomPayload(PomFile file, boolean snapshot) {
try {
DependencyData dependencyData = newDependencyData(file.dependency());
if ("java".equals(dependencyData.platform(file.version()))) {
pomFromGem(file, snapshot, dependencyData);
} else {
pomFromGemspec(file, snapshot, dependencyData);
}
} catch (IOException e) {
file.setException(e);
}
}
private void pomFromGemspec(PomFile file, boolean snapshot, DependencyData dependencyData) throws IOException {
GemspecFile gemspec = file.gemspec(dependencyData);
if (gemspec.notExists()) {
file.markAsNotExists();
} else {
try (InputStream is = store.getInputStream(gemspec)) {
store.memory(gateway.newGemspecHelperFromV2GemInfo(is).pom(snapshot), file);
}
}
}
private void pomFromGem(PomFile file, boolean snapshot, DependencyData dependencyData) throws IOException {
GemFile gem = file.gem(dependencyData);
if (gem.notExists()) {
file.markAsNotExists();
} else {
try (InputStream is = store.getInputStream(gem)) {
store.memory(gateway.newGemspecHelperFromGem(is).pom(snapshot), file);
}
}
}
/**
* retrieve the gem with the right platform and attach it to the GemArtifactFile
*/
protected void setGemArtifactPayload(GemArtifactFile file) {
try {
// the dependency-data is needed to find out
// whether the gem has the default platform or the java platform
GemFile gem = file.gem(newDependencyData(file.dependency()));
if (gem == null) {
file.markAsNotExists();
} else {
// retrieve the gem and set it as payload
store.retrieve(gem);
file.set(gem.get());
}
} catch (IOException e) {
file.setException(e);
}
}
@Override
public PomFile pomSnapshot(String name, String version, String timestamp) {
PomFile file = super.pomSnapshot(name, version, timestamp);
setPomPayload(file, true);
return file;
}
@Override
public PomFile pom(String name, String version) {
PomFile file = super.pom(name, version);
setPomPayload(file, false);
return file;
}
@Override
public GemArtifactFile gemArtifactSnapshot(String name, String version, String timestamp) {
GemArtifactFile file = super.gemArtifactSnapshot(name, version, timestamp);
setGemArtifactPayload(file);
return file;
}
@Override
public GemArtifactFile gemArtifact(String name, String version) {
GemArtifactFile file = super.gemArtifact(name, version);
setGemArtifactPayload(file);
return file;
}
@Override
public Sha1File sha1(RubygemsFile file) {
Sha1File sha = super.sha1(file);
if (sha.notExists()) {
return sha;
}
try (InputStream is = store.getInputStream(file)) {
Sha1Digest digest = new Sha1Digest();
int i = is.read();
while (i != -1) {
digest.update((byte) i);
i = is.read();
}
store.memory(digest.hexDigest(), sha);
} catch (IOException e) {
sha.setException(e);
}
return sha;
}
/**
* load all the dependency data into an object.
*/
protected DependencyData newDependencyData(CompactInfoFile file) throws IOException {
try (InputStream is = store.getInputStream(file)) {
return gateway.newCompactDependencyData(is, file.name(), store.getModified(file));
}
}
protected RubygemsV2GemInfo newRubygemsV2GemInfo(ApiV2File file) throws IOException {
try (InputStream is = store.getInputStream(file)) {
return gateway.newRubygemsV2GemInfo(is, file.name(), file.version(), store.getModified(file));
}
}
@Override
public GemFile gemFile(String name, String version, String platform) {
GemFile gem = super.gemFile(name, version, platform);
store.retrieve(gem);
return gem;
}
@Override
public GemFile gemFile(String filename) {
GemFile gem = super.gemFile(filename);
store.retrieve(gem);
return gem;
}
@Override
public GemspecFile gemspecFile(String name, String version, String platform) {
GemspecFile gemspec = super.gemspecFile(name, version, platform);
store.retrieve(gemspec);
return gemspec;
}
@Override
public GemspecFile gemspecFile(String filename) {
GemspecFile gemspec = super.gemspecFile(filename);
store.retrieve(gemspec);
return gemspec;
}
@Override
public ApiV1File apiV1File(String name) {
ApiV1File file = super.apiV1File(name);
if (!"api_key".equals(name)) {
file.markAsForbidden();
}
return file;
}
}
HostedDELETELayout.java 0000664 0000000 0000000 00000013035 14467014544 0035600 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.jruby.runtime.builtin.IRubyObject;
import org.torquebox.mojo.rubygems.ApiV1File;
import org.torquebox.mojo.rubygems.ApiV2File;
import org.torquebox.mojo.rubygems.DependencyFile;
import org.torquebox.mojo.rubygems.GemFile;
import org.torquebox.mojo.rubygems.GemspecFile;
import org.torquebox.mojo.rubygems.GemspecHelper;
import org.torquebox.mojo.rubygems.IOUtil;
import org.torquebox.mojo.rubygems.CompactInfoFile;
import org.torquebox.mojo.rubygems.RubygemsGateway;
import org.torquebox.mojo.rubygems.SpecsHelper;
import org.torquebox.mojo.rubygems.SpecsIndexFile;
import org.torquebox.mojo.rubygems.SpecsIndexType;
import org.torquebox.mojo.rubygems.SpecsIndexZippedFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
/**
* on hosted rubygems repositories you can delete only gem files. deleting
* a gem file also means to adjust the specs.4.8 indices and their associated
* dependency file as well deleting the gemspec file of the gem.
*
*
* @author christian
* @see HostedGETLayout
*/
// TODO why not using DELETELayout instead of NoopDefaultLayout ?
public class HostedDELETELayout extends NoopDefaultLayout {
public HostedDELETELayout(RubygemsGateway gateway, Storage store) {
super(gateway, store);
}
@Override
public SpecsIndexFile specsIndexFile(String name) {
SpecsIndexFile file = super.specsIndexFile(name);
file.markAsForbidden();
return file;
}
@Override
public GemspecFile gemspecFile(String name, String version, String platform) {
GemspecFile file = super.gemspecFile(name, version, platform);
file.markAsForbidden();
return file;
}
@Override
public GemspecFile gemspecFile(String name) {
GemspecFile file = super.gemspecFile(name);
file.markAsForbidden();
return file;
}
@Override
@Deprecated
public DependencyFile dependencyFile(String name) {
DependencyFile file = super.dependencyFile(name);
file.markAsForbidden();
return file;
}
@Override
public ApiV2File rubygemsInfoV2(String name, String version) {
ApiV2File file = super.rubygemsInfoV2(name, version);
file.markAsForbidden();
return file;
}
@Override
public CompactInfoFile compactInfo(String name) {
CompactInfoFile file = super.compactInfo(name);
file.markAsForbidden();
return file;
}
@Override
public ApiV1File apiV1File(String name) {
ApiV1File file = super.apiV1File(name);
file.markAsForbidden();
return file;
}
@Override
public GemFile gemFile(String name, String version, String platform) {
GemFile file = super.gemFile(name, version, platform);
deleteGemFile(file);
return file;
}
@Override
public GemFile gemFile(String name) {
GemFile file = super.gemFile(name);
deleteGemFile(file);
return file;
}
/**
* delete the gem and its metadata in the specs.4.8 indices and
* dependency file
*/
private void deleteGemFile(GemFile file) {
store.retrieve(file);
try (InputStream is = store.getInputStream(file)) {
GemspecHelper spec = gateway.newGemspecHelperFromGem(is);
deleteSpecFromIndex(spec.gemspec());
// delete dependencies so the next request will recreate it
delete(super.dependencyFile(spec.name()));
// delete the gemspec.rz altogether
delete(super.gemspecFile(file.filename()));
} catch (IOException e) {
file.setException(e);
}
store.delete(file);
}
/**
* delete given spec (a Ruby Object) and delete it from all the specs.4.8 indices.
*/
private void deleteSpecFromIndex(IRubyObject spec) throws IOException {
SpecsHelper specs = gateway.newSpecsHelper();
for (SpecsIndexType type : SpecsIndexType.values()) {
SpecsIndexZippedFile specsIndex = ensureSpecsIndexZippedFile(type);
try (InputStream in = new GZIPInputStream(store.getInputStream(specsIndex))) {
try (InputStream result = specs.deleteSpec(spec, in, type)) {
// if nothing was added the content is NULL
if (result != null) {
store.update(IOUtil.toGzipped(result), specsIndex);
}
}
}
}
}
}
HostedGETLayout.java 0000664 0000000 0000000 00000014027 14467014544 0035257 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.ApiV2File;
import org.torquebox.mojo.rubygems.DependencyFile;
import org.torquebox.mojo.rubygems.DependencyHelper;
import org.torquebox.mojo.rubygems.GemFile;
import org.torquebox.mojo.rubygems.GemspecFile;
import org.torquebox.mojo.rubygems.GemspecHelper;
import org.torquebox.mojo.rubygems.IOUtil;
import org.torquebox.mojo.rubygems.CompactInfoFile;
import org.torquebox.mojo.rubygems.RubygemsGateway;
import org.torquebox.mojo.rubygems.SpecsHelper;
import org.torquebox.mojo.rubygems.SpecsIndexFile;
import org.torquebox.mojo.rubygems.SpecsIndexType;
import org.torquebox.mojo.rubygems.SpecsIndexZippedFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* this hosted layout for HTTP GET will ensure that the zipped version of the specs.4.8
* do exists before retrieving the unzipped ones. it also creates missing gemspec and dependency
* files if missing.
*
* @author christian
*/
public class HostedGETLayout extends GETLayout {
public HostedGETLayout(RubygemsGateway gateway, Storage store) {
super(gateway, store);
}
@Override
protected void retrieveZipped(SpecsIndexZippedFile specs) {
super.retrieveZipped(specs);
if (specs.notExists()) {
try (InputStream content = gateway.newSpecsHelper().createEmptySpecs()) {
// just update in case so no need to deal with concurrency
// since once the file is there no update happen again
store.update(IOUtil.toGzipped(content), specs);
store.retrieve(specs);
} catch (IOException e) {
specs.setException(e);
}
}
}
@Override
public GemspecFile gemspecFile(String name, String version, String platform) {
GemspecFile gemspec = super.gemspecFile(name, version, platform);
if (gemspec.notExists()) {
createGemspec(gemspec);
}
return gemspec;
}
@Override
public GemspecFile gemspecFile(String filename) {
GemspecFile gemspec = super.gemspecFile(filename);
if (gemspec.notExists()) {
createGemspec(gemspec);
}
return gemspec;
}
/**
* create the gemspec from the stored gem file. if the gem file does not
* exists, the GemspecFile
gets makred as NOT_EXISTS.
*/
protected void createGemspec(GemspecFile gemspec) {
GemFile gem = gemspec.gem();
if (gem.notExists()) {
gemspec.markAsNotExists();
} else {
try (InputStream is = store.getInputStream(gemspec.gem())) {
GemspecHelper spec = gateway.newGemspecHelperFromGem(is);
// just update in case so no need to deal with concurrency
// since once the file is there no update happen again
store.update(spec.getRzInputStream(), gemspec);
store.retrieve(gemspec);
} catch (IOException e) {
gemspec.setException(e);
}
}
}
@Override
@Deprecated
public DependencyFile dependencyFile(String name) {
DependencyFile file = super.dependencyFile(name);
store.retrieve(file);
if (file.notExists()) {
createDependency(file);
}
return file;
}
@Override
public ApiV2File rubygemsInfoV2(String name, String version) {
ApiV2File file = super.rubygemsInfoV2(name, version);
store.retrieve(file);
return file;
}
@Override
public CompactInfoFile compactInfo(String name) {
CompactInfoFile file = super.compactInfo(name);
store.retrieve(file);
return file;
}
/**
* create the DependencyFile
for the given gem name
*/
protected void createDependency(DependencyFile file) {
try {
SpecsIndexFile specs = specsIndexFile(SpecsIndexType.RELEASE);
store.retrieve(specs);
if (specs.hasException()) {
file.setException(specs.getException());
return;
}
List
*
* RubygemsFileFactory
*
* @author christian
*/
public interface Layout
extends RubygemsFileFactory {
/**
* some layout needs to be able to "upload" gem-files
*
* @param is the InputStream
which is used to store the given file
* @param file which can be GemFile
or ApiV1File
with name "gem"
*/
void addGem(InputStream is, RubygemsFile file);
} NoopDefaultLayout.java 0000664 0000000 0000000 00000012016 14467014544 0035705 0 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.BundlerApiFile;
import org.torquebox.mojo.rubygems.Directory;
import org.torquebox.mojo.rubygems.GemArtifactFile;
import org.torquebox.mojo.rubygems.IOUtil;
import org.torquebox.mojo.rubygems.MavenMetadataFile;
import org.torquebox.mojo.rubygems.MavenMetadataSnapshotFile;
import org.torquebox.mojo.rubygems.PomFile;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.RubygemsGateway;
import org.torquebox.mojo.rubygems.Sha1File;
import org.torquebox.mojo.rubygems.SpecsIndexType;
import org.torquebox.mojo.rubygems.SpecsIndexZippedFile;
import java.io.IOException;
import java.io.InputStream;
/**
* adds default behavior for all RubygemsFile
:
*
* DefaultLayout
InputStream
s as payload.
*
* @author christian
*/
public class SimpleStorage
implements Storage {
private final SecureRandom random = new SecureRandom();
private final File basedir;
/**
* create the storage with given base-directory.
*/
public SimpleStorage(File basedir) {
this.basedir = basedir;
this.random.setSeed(System.currentTimeMillis());
}
@Override
public InputStream getInputStream(RubygemsFile file) throws IOException {
if (file.hasException()) {
throw new IOException(file.getException());
}
InputStream is;
if (file.get() == null) {
is = Files.newInputStream(toPath(file));
} else {
is = ((StreamLocation) file.get()).openStream();
}
// reset state since we have a payload and no exceptions
file.resetState();
return is;
}
/**
* convert RubygemsFile
into a Path
.
*/
protected Path toPath(RubygemsFile file) {
return new File(basedir, file.storagePath()).toPath();
}
@Override
public long getModified(RubygemsFile file) {
return toPath(file).toFile().lastModified();
}
@Override
public void retrieve(RubygemsFile file) {
file.resetState();
Path path = toPath(file);
if (Files.notExists(path)) {
file.markAsNotExists();
} else {
try {
set(file, path);
} catch (IOException e) {
file.setException(e);
}
}
}
@Override
public void retrieve(DependencyFile file) {
retrieve((RubygemsFile) file);
}
@Override
public void retrieve(CompactInfoFile file) {
retrieve((RubygemsFile) file);
}
@Override
public void retrieve(SpecsIndexZippedFile file) {
retrieve((RubygemsFile) file);
}
@Override
public void retrieve(SpecsIndexFile file) {
SpecsIndexZippedFile zipped = file.zippedSpecsIndexFile();
retrieve(zipped);
if (zipped.notExists()) {
file.markAsNotExists();
}
if (zipped.hasException()) {
file.setException(zipped.getException());
} else {
file.set(new URLGzipStreamLocation((StreamLocation) zipped.get()));
}
}
@Override
public void create(InputStream is, RubygemsFile file) {
Path target = toPath(file);
Path mutex = target.resolveSibling(target.getFileName() + ".lock");
Path source = target.resolveSibling("tmp." + Math.abs(random.nextLong()));
try {
createDirectory(source.getParent());
Files.createFile(mutex);
Files.copy(is, source);
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
set(file, target);
} catch (FileAlreadyExistsException e) {
mutex = null;
file.markAsTempUnavailable();
} catch (IOException e) {
file.setException(e);
} finally {
if (mutex != null) {
mutex.toFile().delete();
}
source.toFile().delete();
}
}
/**
* set the payload
*
* @param file which gets the payload
* @param path the path to the payload
* @throws MalformedURLException
*/
private void set(RubygemsFile file, Path path) throws MalformedURLException {
file.set(new URLStreamLocation(path.toUri().toURL()));
}
@Override
public void update(InputStream is, RubygemsFile file) {
Path target = toPath(file);
Path source = target.resolveSibling("tmp." + Math.abs(random.nextLong()));
try {
createDirectory(source.getParent());
Files.copy(is, source);
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
set(file, target);
} catch (IOException e) {
file.setException(e);
} finally {
source.toFile().delete();
}
}
/**
* create a directory if it is not existing
*/
protected void createDirectory(Path parent) throws IOException {
if (!Files.exists(parent)) {
Files.createDirectories(parent);
}
}
@Override
public void delete(RubygemsFile file) {
try {
Files.deleteIfExists(toPath(file));
} catch (IOException e) {
file.setException(e);
}
}
@Override
public void memory(ByteArrayInputStream data, RubygemsFile file) {
file.set(new BytesStreamLocation(data));
}
@Override
public void memory(String data, RubygemsFile file) {
memory(new ByteArrayInputStream(data.getBytes()), file);
}
@Override
public String[] listDirectory(Directory dir) {
String[] list = toPath(dir).toFile().list();
if (list == null) {
list = new String[0];
}
return list;
}
static interface StreamLocation {
InputStream openStream() throws IOException;
}
static class URLStreamLocation implements StreamLocation {
public static final String RUBYGEMS_TOOLS_USER_AGENT = "org.jruby.maven:rubygems-tools";
private URL url;
private Base64 base64 = new Base64();
URLStreamLocation(URL url) {
this.url = url;
}
public URLConnection openConnection() throws IOException {
URLConnection con = url.openConnection();
con.setRequestProperty("User-Agent", RUBYGEMS_TOOLS_USER_AGENT);
String userinfo = this.url.getUserInfo();
if (userinfo != null) {
String basicAuth = "Basic " + base64.encodeBase64String(URLDecoder.decode(userinfo, "UTF-8").getBytes(StandardCharsets.UTF_8));
con.setRequestProperty("Authorization", basicAuth);
}
return con;
}
@Override
public InputStream openStream() throws IOException {
return openConnection().getInputStream();
}
}
static class BytesStreamLocation implements StreamLocation {
private ByteArrayInputStream stream;
BytesStreamLocation(ByteArrayInputStream stream) {
this.stream = stream;
}
@Override
public InputStream openStream() throws IOException {
return stream;
}
}
static class URLGzipStreamLocation implements StreamLocation {
private StreamLocation stream;
URLGzipStreamLocation(StreamLocation stream) {
this.stream = stream;
}
@Override
public InputStream openStream() throws IOException {
return new GZIPInputStream(stream.openStream());
}
}
}
mavengem-mavengem-2.0.1/rubygems-tools/src/main/java/org/torquebox/mojo/rubygems/layout/Storage.java0000664 0000000 0000000 00000007014 14467014544 0033754 0 ustar 00root root 0000000 0000000 /*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.torquebox.mojo.rubygems.layout;
import org.torquebox.mojo.rubygems.CompactInfoFile;
import org.torquebox.mojo.rubygems.DependencyFile;
import org.torquebox.mojo.rubygems.Directory;
import org.torquebox.mojo.rubygems.RubygemsFile;
import org.torquebox.mojo.rubygems.SpecsIndexFile;
import org.torquebox.mojo.rubygems.SpecsIndexZippedFile;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* storage abstraction using RubygemsFile
. all the CRUD methods do set the
* the payload. these CRUD methods do NOT throw exceptions but sets those exceptions
* as payload of the passed in RubygemsFile
.
* SpecsIndexFile
, SpecsIndexZippedFile
* and DependencyFile
needs to be merged, all other files will be served the first find.
*
* @author christian
*/
public interface Storage {
/**
* create the given file from an InputStream
.
*/
void create(InputStream is, RubygemsFile file);
/**
* retrieve the payload of the given file.
*/
void retrieve(RubygemsFile file);
/**
* retrieve the payload of the given file.
*/
void retrieve(SpecsIndexFile file);
/**
* retrieve the payload of the given file.
*/
void retrieve(SpecsIndexZippedFile file);
/**
* retrieve the payload of the given file.
*/
void retrieve(DependencyFile file);
/**
* retrieve the payload of the given file.
*/
void retrieve(CompactInfoFile file);
/**
* update the given file from an InputStream
.
*/
void update(InputStream is, RubygemsFile file);
/**
* delete the given file.
*/
void delete(RubygemsFile file);
/**
* use the String
to generate the payload
* for the RubygemsFile
instance.
*/
void memory(ByteArrayInputStream data, RubygemsFile file);
/**
* use the String
can converts it with to byte
array
* for the the payload of the RubygemsFile
instance.
*/
void memory(String data, RubygemsFile file);
/**
* get an inputStream
to actual file from the physical storage.
*
* @throws IOException on IO related errors or
* wrapped the exception if the payload has an exception.
*/
InputStream getInputStream(RubygemsFile file) throws IOException;
/**
* get the last-modified unix time for the given file from the physical storage location.
*/
long getModified(RubygemsFile file);
/**
* list given Directory
from the physical storage location.
*/
String[] listDirectory(Directory dir);
}
mavengem-mavengem-2.0.1/rubygems-tools/src/main/resources/ 0000775 0000000 0000000 00000000000 14467014544 0023637 5 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/resources/nexus/ 0000775 0000000 0000000 00000000000 14467014544 0025001 5 ustar 00root root 0000000 0000000 mavengem-mavengem-2.0.1/rubygems-tools/src/main/resources/nexus/bundle_runner.rb 0000664 0000000 0000000 00000003135 14467014544 0030172 0 ustar 00root root 0000000 0000000 #
# Sonatype Nexus (TM) Open Source Version
# Copyright (c) 2008-present Sonatype, Inc.
# All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
#
# This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
# which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
#
# Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
# of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
# Eclipse Foundation. All other trademarks are the property of their respective owners.
#
require 'bundler'
require 'bundler/cli'
require 'stringio'
module Nexus
class BundleRunner
def _out
@out ||= StringIO.new
end
def _err
@err ||= StringIO.new
end
def exec( *args )
$stdout = _out
$stderr = _err
ENV['PATH'] ||= '' # just make sure bundler has a PATH variable
Bundler::CLI.start( args )
_out.string
rescue SystemExit => e
raise err.string if e.exit_code != 0
_out.string
rescue Exception => e
STDOUT.puts _out.string
STDERR.puts _err.string
trace = e.backtrace.join("\n\t")
raise "#{e.message}\n\t#{trace}"
ensure
$stdout = STDOUT
$stderr = STDERR
#Thor::Shell::Basic.stdout.reopen
end
end
end
# this makes it easy for a scripting container to
# create an instance of this class
Nexus::BundleRunner
mavengem-mavengem-2.0.1/rubygems-tools/src/main/resources/nexus/check.rb 0000664 0000000 0000000 00000002402 14467014544 0026401 0 ustar 00root root 0000000 0000000 #
# Sonatype Nexus (TM) Open Source Version
# Copyright (c) 2008-present Sonatype, Inc.
# All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
#
# This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
# which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
#
# Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
# of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
# Eclipse Foundation. All other trademarks are the property of their respective owners.
#
module Nexus
class Check
def check_gemspec_rz(gemfile, gemspec)
spec_from_gem = Gem::Package.new( gemfile ).spec
spec_from_gemspec = Marshal.load( Zlib::Inflate.inflate( Gem.read_binary( gemspec) ) )
spec_from_gem == spec_from_gemspec
end
def check_spec_name( gemfile )
Gem::Format.from_file_by_path( gemfile ).spec.name
end
def specs_size( specsfile )
specs = Marshal.load( Gem.read_binary( specsfile ) )
specs.size
end
end
end
Nexus::Check.new
mavengem-mavengem-2.0.1/rubygems-tools/src/main/resources/nexus/compact_dependency_data.rb 0000664 0000000 0000000 00000004465 14467014544 0032154 0 ustar 00root root 0000000 0000000 require 'nexus/rubygems_helper'
java_import org.torquebox.mojo.rubygems.DependencyData
# Dependency data based on the compact index format
module Nexus
class CompactDependencyData
include DependencyData
include RubygemsHelper
attr_reader :name, :modified
# contructor parsing dependency data
# @param data [Array, IO, String] either the unmarshalled array or
# the stream or filename to the marshalled data
def initialize( data, name, modified )
data = read_binary(data)
@name = name
@modified = modified
@versions = {}
@dependencies = {}
# Format is as follows:
# First line: "---"
# [version-platform] [space] [comma-delimited-deps] [pipe] [checksum] [comma] [min_ruby] [comma] [min_rubygems] [newline]
# The version-platform is [version] [dash] [platform].
# The deps and mins are specified as [gemname] [colon] [comparator] [space] [version].
data.lines.filter_map do |line|
line.match(/^(?