Skip to content

Commit

Permalink
[SHRINKWRAP-413] Add a UUID field to Archives; update the Serializati…
Browse files Browse the repository at this point in the history
…on mechanism and account for backwards-compatibility in the wire protocol.
  • Loading branch information
ALRubinger committed Jul 26, 2012
1 parent 4b77293 commit dd241ea
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 41 deletions.
22 changes: 16 additions & 6 deletions api/src/main/java/org/jboss/shrinkwrap/api/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public interface Archive<T extends Archive<T>> extends Assignable {
*/
String getName();

/**
* Obtains a globally-unique identifier for this {@link Archive}
*
* @return
*/
String getId();

/**
* Adds the specified asset under the specified path into the target context
*
Expand Down Expand Up @@ -185,11 +192,12 @@ public interface Archive<T extends Archive<T>> extends Assignable {
T addAsDirectories(ArchivePath... paths) throws IllegalArgumentException;

/**
* Add an array of listeners for call back based.
*
* @param listener CallBack on add
* @return This archive
*/
* Add an array of listeners for call back based.
*
* @param listener
* CallBack on add
* @return This archive
*/
T addHandlers(ArchiveEventHandler... handlers);

/**
Expand Down Expand Up @@ -361,7 +369,8 @@ <X extends Archive<X>> Collection<X> getAsType(Class<X> type, Filter<ArchivePath
Node delete(String archivePath) throws IllegalArgumentException;

/**
* Obtains all assets in this archive, along with their respective paths. The returned Map will be an immutable view.
* Obtains all assets in this archive, along with their respective paths. The returned Map will be an immutable
* view.
*
* @return
*/
Expand Down Expand Up @@ -527,6 +536,7 @@ T add(Archive<?> archive, ArchivePath path, Class<? extends StreamExporter> expo
*
* @return
*/
@Override
String toString();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -48,6 +49,7 @@
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.jboss.shrinkwrap.spi.ArchiveFormatAssociable;
import org.jboss.shrinkwrap.spi.Configurable;
import org.jboss.shrinkwrap.spi.Identifiable;

/**
* Base implementation of {@link Archive}. Contains support for operations (typically overloaded) that are not specific
Expand All @@ -57,7 +59,8 @@
* @author <a href="mailto:baileyje@gmail.com">John Bailey</a>
* @version $Revision: $
*/
public abstract class ArchiveBase<T extends Archive<T>> implements Archive<T>, Configurable, ArchiveFormatAssociable {
public abstract class ArchiveBase<T extends Archive<T>> implements Archive<T>, Configurable, ArchiveFormatAssociable,
Identifiable {

// -------------------------------------------------------------------------------------||
// Class Members -----------------------------------------------------------------------||
Expand All @@ -82,6 +85,11 @@ public abstract class ArchiveBase<T extends Archive<T>> implements Archive<T>, C
*/
private final Configuration configuration;

/**
* Globally-unique ID for this archive
*/
private String id;

// -------------------------------------------------------------------------------------||
// Constructor -------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||
Expand All @@ -106,6 +114,7 @@ protected ArchiveBase(final String name, final Configuration configuration) thro
// Set
this.name = name;
this.configuration = configuration;
this.setId(UUID.randomUUID().toString());
}

// -------------------------------------------------------------------------------------||
Expand Down Expand Up @@ -424,10 +433,27 @@ public T addAsDirectories(final String... paths) throws IllegalArgumentException
*
* @see org.jboss.shrinkwrap.api.Archive#getName()
*/
@Override
public final String getName() {
return name;
}

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.Archive#getId()
*/
@Override
public String getId() {
return this.id.toString();
}

@Override
public void setId(final String id) throws IllegalArgumentException {
Validate.notNullOrEmpty(id, "ID must be specified");
this.id = id;
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.shrinkwrap.impl.base;

import java.util.logging.Logger;

import org.jboss.shrinkwrap.api.Assignable;
import org.jboss.shrinkwrap.spi.Identifiable;

/**
* {@link Assignable} implementation view of an {@link Identifiable}.
*
* @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
* @version $Revision: $
*/
public class IdentifiableArchiveImpl extends AssignableBase<ArchiveBase<?>> implements Identifiable {

/**
* Logger
*/
@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(IdentifiableArchiveImpl.class.getName());

public IdentifiableArchiveImpl(final ArchiveBase<?> archive) {
super(archive);
}

@Override
public String getId() {
return this.getArchive().getId();
}

@Override
public void setId(final String id) throws IllegalArgumentException {
this.getArchive().setId(id);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,15 @@ public T addAsDirectory(String path) throws IllegalArgumentException {
/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.Archive#addHandlers(org.jboss.shrinkwrap.api.Filter, org.jboss.shrinkwrap.api.ArchiveEventHandler)
* @see org.jboss.shrinkwrap.api.Archive#addHandlers(org.jboss.shrinkwrap.api.Filter,
* org.jboss.shrinkwrap.api.ArchiveEventHandler)
*/
@Override
public T addHandlers(ArchiveEventHandler... handlers) {
for (ArchiveEventHandler handler : handlers) {
this.getArchive().addHandlers(handler);
}
return covarientReturn();
for (ArchiveEventHandler handler : handlers) {
this.getArchive().addHandlers(handler);
}
return covarientReturn();
}

/**
Expand Down Expand Up @@ -318,12 +319,13 @@ public T merge(final Archive<?> source, final String path) throws IllegalArgumen
/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.Archive#move(org.jboss.shrinkwrap.api.ArchivePath, org.jboss.shrinkwrap.api.ArchivePath)
* @see org.jboss.shrinkwrap.api.Archive#move(org.jboss.shrinkwrap.api.ArchivePath,
* org.jboss.shrinkwrap.api.ArchivePath)
*/
@Override
public T move(ArchivePath source, ArchivePath target) throws IllegalArgumentException, IllegalArchivePathException {
this.getArchive().move(source, target);
return covarientReturn();
this.getArchive().move(source, target);
return covarientReturn();
}

/**
Expand All @@ -333,8 +335,8 @@ public T move(ArchivePath source, ArchivePath target) throws IllegalArgumentExce
*/
@Override
public T move(String source, String target) throws IllegalArgumentException, IllegalArchivePathException {
this.getArchive().move(source, target);
return covarientReturn();
this.getArchive().move(source, target);
return covarientReturn();
}

/**
Expand Down Expand Up @@ -508,6 +510,17 @@ public String getName() {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.Archive#getId()
*/
@Override
public String getId() {
return this.getArchive().getId();
}

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.Archive#shallowCopy()
*/
@Override
Expand All @@ -516,7 +529,7 @@ public Archive<T> shallowCopy() {
// using the same underlying configuration
final Class<T> actualClass = this.getActualClass();
final Archive<?> underlyingArchive = this.getArchive();
final Configuration existingConfig= ((Configurable)underlyingArchive).getConfiguration();
final Configuration existingConfig = ((Configurable) underlyingArchive).getConfiguration();
final Domain domain = ShrinkWrap.createDomain(existingConfig);
final ArchiveFactory factory = domain.getArchiveFactory();
final Archive<T> newArchive = factory.create(actualClass, this.getName());
Expand All @@ -529,6 +542,7 @@ public Archive<T> shallowCopy() {

/**
* {@inheritDoc}
*
* @see java.lang.Object#toString()
*/
@Override
Expand All @@ -538,6 +552,7 @@ public String toString() {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.Archive#toString(boolean)
*/
@Override
Expand All @@ -557,6 +572,7 @@ public String toString(final Formatter formatter) throws IllegalArgumentExceptio

/**
* {@inheritDoc}
*
* @see java.lang.Object#hashCode()
*/
@Override
Expand All @@ -566,6 +582,7 @@ public int hashCode() {

/**
* {@inheritDoc}
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
Expand Down Expand Up @@ -595,6 +612,7 @@ public boolean equals(final Object obj) {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#setManifest(java.lang.String)
*/
@Override
Expand All @@ -605,6 +623,7 @@ public final T setManifest(String resourceName) {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#setManifest(java.io.File)
*/
@Override
Expand All @@ -615,6 +634,7 @@ public T setManifest(File resource) throws IllegalArgumentException {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#setManifest(java.net.URL)
*/
@Override
Expand All @@ -625,6 +645,7 @@ public T setManifest(URL resource) throws IllegalArgumentException {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#setManifest(org.jboss.shrinkwrap.api.asset.Asset)
*/
@Override
Expand All @@ -635,6 +656,7 @@ public T setManifest(Asset resource) throws IllegalArgumentException {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#setManifest(java.lang.Package, java.lang.String)
*/
@Override
Expand All @@ -648,6 +670,7 @@ public T setManifest(Package resourcePackage, String resourceName) throws Illega

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#addAsManifestResource(java.lang.String)
*/
@Override
Expand All @@ -658,6 +681,7 @@ public final T addAsManifestResource(String resourceName) {

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#addAsManifestResource(java.io.File)
*/
@Override
Expand All @@ -668,7 +692,9 @@ public T addAsManifestResource(File resource) throws IllegalArgumentException {

/**
* {@inheritDoc}
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#addAsManifestResource(java.lang.String, java.lang.String)
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#addAsManifestResource(java.lang.String,
* java.lang.String)
*/
@Override
public T addAsManifestResource(String resourceName, String target) throws IllegalArgumentException {
Expand All @@ -680,6 +706,7 @@ public T addAsManifestResource(String resourceName, String target) throws Illega

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.api.container.ManifestContainer#addAsManifestResource(java.io.File, java.lang.String)
*/
@Override
Expand Down Expand Up @@ -900,6 +927,7 @@ public T addAsManifestResource(Package resourcePackage, String resourceName, Arc
/**
* {@inheritDoc}
*/
@Override
public T addManifest() throws IllegalArgumentException {
return addAsManifestResource(DEFAULT_MANIFEST, ManifestContainer.DEFAULT_MANIFEST_NAME);
}
Expand Down Expand Up @@ -1284,6 +1312,7 @@ public T addClass(final String fullyQualifiedClassName, final ClassLoader cl) th
*
* @see org.jboss.declarchive.api.container.ClassContainer#addClasses(java.lang.Class<?>[])
*/
@Override
public T addClasses(Class<?>... classes) throws IllegalArgumentException {
Validate.notNull(classes, "Classes must be specified");

Expand All @@ -1308,6 +1337,7 @@ public T addClasses(Class<?>... classes) throws IllegalArgumentException {
* The added classes
* @return
*/
@Override
public boolean include(ArchivePath path) {
ArchivePath classArchivePath = AssetUtil.getFullPathForClassResource(clazz);
String expression = classArchivePath.get().replace(".class", "\\$.*");
Expand Down Expand Up @@ -1479,6 +1509,7 @@ public void classFound(String className) {
*
* @see org.jboss.shrinkwrap.api.container.LibraryContainer#addAsLibrary(org.jboss.shrinkwrap.api.Archive)
*/
@Override
public T addAsLibrary(final Archive<?> archive) throws IllegalArgumentException {
Validate.notNull(archive, "Archive must be specified");
// Libraries are JARs, so add as ZIP
Expand Down

0 comments on commit dd241ea

Please sign in to comment.