Permalink
Browse files

Grab descriptor as well, if there is one; TODO -- test this.

  • Loading branch information...
1 parent 0e1aa4a commit d59d843034f52cf0844e6758fdfa3ae3664436d5 @alesj alesj committed Oct 6, 2012
@@ -17,12 +17,12 @@
package com.redhat.ceylon.cmr.api;
+import java.io.Serializable;
+
import com.redhat.ceylon.cmr.spi.ContentOptions;
import com.redhat.ceylon.cmr.spi.Node;
import com.redhat.ceylon.cmr.spi.OpenNode;
-import java.io.Serializable;
-
/**
* Artifact lookup context.
*
@@ -46,6 +46,7 @@
private boolean ignoreSHA;
private boolean throwErrorIfMissing;
private boolean forceOperation;
+ private boolean forceDescriptorCheck;
private boolean fetchSingleArtifact;
public ArtifactContext(String name, String version) {
@@ -146,6 +147,14 @@ public void setForceOperation(boolean forceOperation) {
this.forceOperation = forceOperation;
}
+ public boolean isForceDescriptorCheck() {
+ return forceDescriptorCheck;
+ }
+
+ public void setForceDescriptorCheck(boolean forceDescriptorCheck) {
+ this.forceDescriptorCheck = forceDescriptorCheck;
+ }
+
public boolean isFetchSingleArtifact() {
return fetchSingleArtifact;
}
@@ -162,4 +171,8 @@ public String toString() {
public boolean forceOperation() {
return isForceOperation();
}
+
+ public boolean forceDescriptorCheck() {
+ return isForceDescriptorCheck();
+ }
}
@@ -18,6 +18,8 @@
import java.util.List;
+import com.redhat.ceylon.cmr.spi.Node;
+
/**
* Dependency resolver spi / api.
*
@@ -31,5 +33,13 @@
* @return dependencies list or null if cannot resolve
*/
List<ModuleInfo> resolve(ArtifactResult parent);
+
+ /**
+ * Get descriptor if exists.
+ *
+ * @param artifact the artifact
+ * @return descriptor or null
+ */
+ Node descriptor(Node artifact);
}
@@ -19,6 +19,8 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import com.redhat.ceylon.cmr.spi.Node;
+
/**
* Plugable dependencies utils mechanism.
*
@@ -48,6 +50,15 @@ public void removeResolver(DependencyResolver resolver) {
return null;
}
+ public Node descriptor(Node artifact) {
+ for (DependencyResolver dr : resolvers) {
+ Node descriptor = dr.descriptor(artifact);
+ if (descriptor != null)
+ return descriptor;
+ }
+ return null;
+ }
+
@Override
public String toString() {
return resolvers.toString();
@@ -16,27 +16,25 @@
package com.redhat.ceylon.cmr.impl;
-import com.redhat.ceylon.cmr.api.*;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import com.redhat.ceylon.cmr.api.ArtifactContext;
+import com.redhat.ceylon.cmr.api.ArtifactResult;
+import com.redhat.ceylon.cmr.api.ArtifactResultType;
+import com.redhat.ceylon.cmr.api.ImportType;
+import com.redhat.ceylon.cmr.api.ModuleInfo;
+import com.redhat.ceylon.cmr.api.RepositoryException;
+import com.redhat.ceylon.cmr.api.RepositoryManager;
+
/**
* Abstract, use Jandex to read off Module info.
*
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
public abstract class AbstractCeylonArtifactResult extends AbstractArtifactResult {
- private final static DependencyResolvers resolvers;
-
- static {
- resolvers = new DependencyResolvers();
- resolvers.addResolver(PropertiesDependencyResolver.INSTANCE);
- resolvers.addResolver(BytecodeUtils.INSTANCE);
- }
-
private RepositoryManager manager;
protected AbstractCeylonArtifactResult(RepositoryManager manager, String name, String version) {
@@ -49,7 +47,7 @@ public ArtifactResultType type() {
}
public List<ArtifactResult> dependencies() throws RepositoryException {
- List<ModuleInfo> infos = resolvers.resolve(this);
+ List<ModuleInfo> infos = Configuration.getResolvers().resolve(this);
// TODO -- perhaps null is not valid?
if (infos == null || infos.isEmpty())
return Collections.emptyList();
@@ -16,11 +16,6 @@
package com.redhat.ceylon.cmr.impl;
-import com.redhat.ceylon.cmr.api.ArtifactResult;
-import com.redhat.ceylon.cmr.api.DependencyResolver;
-import com.redhat.ceylon.cmr.api.ModuleInfo;
-import org.jboss.jandex.*;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -29,6 +24,19 @@
import java.util.Collections;
import java.util.List;
+import com.redhat.ceylon.cmr.api.ArtifactResult;
+import com.redhat.ceylon.cmr.api.DependencyResolver;
+import com.redhat.ceylon.cmr.api.ModuleInfo;
+import com.redhat.ceylon.cmr.spi.Node;
+import org.jboss.jandex.AnnotationInstance;
+import org.jboss.jandex.AnnotationValue;
+import org.jboss.jandex.ClassInfo;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.Index;
+import org.jboss.jandex.IndexReader;
+import org.jboss.jandex.Indexer;
+import org.jboss.jandex.JarIndexer;
+
/**
* Byte hacks / utils.
*
@@ -51,6 +59,10 @@ private BytecodeUtils() {
return readModuleInformation(parent.name(), parent.artifact());
}
+ public Node descriptor(Node artifact) {
+ return null; // artifact is a descriptor
+ }
+
/**
* Read module info from bytecode.
*
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2011 Red Hat inc. and third party contributors as noted
+ * by the author tags.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.redhat.ceylon.cmr.impl;
+
+import com.redhat.ceylon.cmr.api.DependencyResolvers;
+
+/**
+ * Simple config holder.
+ *
+ * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ */
+public class Configuration {
+ private static final DependencyResolvers resolvers;
+
+ static {
+ resolvers = new DependencyResolvers();
+ resolvers.addResolver(PropertiesDependencyResolver.INSTANCE);
+ resolvers.addResolver(BytecodeUtils.INSTANCE);
+ }
+
+ public static DependencyResolvers getResolvers() {
+ return resolvers;
+ }
+}
@@ -16,17 +16,18 @@
package com.redhat.ceylon.cmr.impl;
-import com.redhat.ceylon.cmr.api.ArtifactResult;
-import com.redhat.ceylon.cmr.api.DependencyResolver;
-import com.redhat.ceylon.cmr.api.ModuleInfo;
-
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import com.redhat.ceylon.cmr.api.ArtifactResult;
+import com.redhat.ceylon.cmr.api.DependencyResolver;
+import com.redhat.ceylon.cmr.api.ModuleInfo;
+import com.redhat.ceylon.cmr.spi.Node;
+
/**
* Read module info from properties.
*
@@ -58,4 +59,8 @@
throw new RuntimeException(e);
}
}
+
+ public Node descriptor(Node artifact) {
+ return NodeUtils.firstParent(artifact).getChild("module.properties");
+ }
}
@@ -39,7 +39,6 @@
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
public class RootRepositoryManager extends AbstractNodeRepositoryManager {
-
private final FileContentStore fileContentStore;
private static File getRootDir() {
@@ -121,6 +120,15 @@ protected File putContent(ArtifactContext context, Node node, InputStream stream
}
}
+ // only check for jars or forced checks
+ if (ArtifactContext.JAR.equals(context.getSuffix()) || context.forceDescriptorCheck()) {
+ // transfer descriptor as well, if there is one
+ final Node descriptor = Configuration.getResolvers().descriptor(node);
+ if (descriptor != null && descriptor.hasBinaries()) {
+ fileContentStore.putContent(descriptor, descriptor.getInputStream(), context);
+ }
+ }
+
// refresh markers from root to this newly put node
final List<String> paths = NodeUtils.toLabelPath(node);
OpenNode current = getRoot();
@@ -30,6 +30,10 @@
public boolean forceOperation() {
return false;
}
+
+ public boolean forceDescriptorCheck() {
+ return false;
+ }
};
/**
@@ -38,4 +42,11 @@ public boolean forceOperation() {
* @return true if forced, false otherwise
*/
boolean forceOperation();
+
+ /**
+ * Do we force descriptor check.
+ *
+ * @return true if forced, false otherwise
+ */
+ boolean forceDescriptorCheck();
}

0 comments on commit d59d843

Please sign in to comment.