Skip to content

Commit

Permalink
Expose archive methods to beforeExtract method.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcin committed Sep 16, 2019
1 parent 6c2364f commit b9a96a4
Show file tree
Hide file tree
Showing 13 changed files with 564 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>net.adamcin.oakpal</groupId>
<artifactId>oakpal</artifactId>
<version>1.4.3-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>net.adamcin.oakpal</groupId>
<artifactId>oakpal</artifactId>
<version>1.4.3-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
92 changes: 92 additions & 0 deletions core/src/main/java/net/adamcin/oakpal/core/ArchiveInf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2019 Mark Adamcin
*
* 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 net.adamcin.oakpal.core;

import org.apache.jackrabbit.vault.fs.api.VaultInputSource;
import org.apache.jackrabbit.vault.fs.config.MetaInf;
import org.apache.jackrabbit.vault.fs.io.Archive;
import org.apache.jackrabbit.vault.packaging.PackageProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.InputStream;

/**
* Facade interface for {@link PackageProperties} that also exposes {@link org.apache.jackrabbit.vault.fs.io.Archive}
* methods for reading entries.
*/
public interface ArchiveInf extends PackageProperties {

/**
* Opens an input stream for the given entry
*
* @param entry the entry
* @return the input stream or {@code null} if the entry can't be read
* @throws IOException if an error occurs
*/
@Nullable
InputStream openInputStream(@Nullable Archive.Entry entry) throws IOException;

/**
* Returns an input source for the given entry
*
* @param entry the entry
* @return the input source or {@code null} if the entry can't be read
* @throws IOException if an error occurs
*/
@Nullable
VaultInputSource getInputSource(@Nullable Archive.Entry entry) throws IOException;

/**
* Returns the entry that specifies the "jcr_root". if no such
* entry exists, {@code null} is returned.
*
* @return the jcr_root entry or {@code null}
* @throws IOException if an error occurs
*/
@Nullable
Archive.Entry getJcrRoot() throws IOException;

/**
* Returns the root entry.
*
* @return the root entry.
* @throws IOException if an error occurs
*/
@NotNull
Archive.Entry getRoot() throws IOException;

/**
* Returns the meta inf. If the archive provides no specific meta data,
* a default, empty meta inf is returned.
*
* @return the meta inf.
*/
@NotNull
MetaInf getMetaInf();

/**
* Returns the entry specified by path.
*
* @param path the path
* @return the entry or {@code null} if not found.
* @throws IOException if an error occurs
*/
@Nullable
Archive.Entry getEntry(@NotNull String path) throws IOException;
}
159 changes: 159 additions & 0 deletions core/src/main/java/net/adamcin/oakpal/core/ArchiveInfImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright 2019 Mark Adamcin
*
* 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 net.adamcin.oakpal.core;

import org.apache.jackrabbit.vault.fs.api.VaultInputSource;
import org.apache.jackrabbit.vault.fs.config.MetaInf;
import org.apache.jackrabbit.vault.fs.io.AccessControlHandling;
import org.apache.jackrabbit.vault.fs.io.Archive;
import org.apache.jackrabbit.vault.packaging.Dependency;
import org.apache.jackrabbit.vault.packaging.PackageException;
import org.apache.jackrabbit.vault.packaging.PackageId;
import org.apache.jackrabbit.vault.packaging.PackageProperties;
import org.apache.jackrabbit.vault.packaging.PackageType;
import org.apache.jackrabbit.vault.packaging.SubPackageHandling;
import org.apache.jackrabbit.vault.packaging.VaultPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;

final class ArchiveInfImpl implements ArchiveInf {
final PackageProperties packageProperties;
final Archive archive;

ArchiveInfImpl(final @NotNull PackageProperties packageProperties, final @NotNull Archive archive) {
this.packageProperties = packageProperties;
this.archive = archive;
}

@Override
public @Nullable InputStream openInputStream(final @Nullable Archive.Entry entry) throws IOException {
return archive.openInputStream(entry);
}

@Override
public @Nullable VaultInputSource getInputSource(final @Nullable Archive.Entry entry) throws IOException {
return archive.getInputSource(entry);
}

@Override
public @Nullable Archive.Entry getJcrRoot() throws IOException {
return archive.getJcrRoot();
}

@Override
public @NotNull Archive.Entry getRoot() throws IOException {
return archive.getRoot();
}

@Override
public @NotNull MetaInf getMetaInf() {
return archive.getMetaInf();
}

@Override
public @Nullable Archive.Entry getEntry(final @NotNull String path) throws IOException {
return archive.getEntry(path);
}

@Override
public PackageId getId() {
return packageProperties.getId();
}

@Override
public Calendar getLastModified() {
return packageProperties.getLastModified();
}

@Override
public String getLastModifiedBy() {
return packageProperties.getLastModifiedBy();
}

@Override
public Calendar getCreated() {
return packageProperties.getCreated();
}

@Override
public String getCreatedBy() {
return packageProperties.getCreatedBy();
}

@Override
public Calendar getLastWrapped() {
return packageProperties.getLastWrapped();
}

@Override
public String getLastWrappedBy() {
return packageProperties.getLastWrappedBy();
}

@Override
public String getDescription() {
return packageProperties.getDescription();
}

@Override
public boolean requiresRoot() {
return packageProperties.requiresRoot();
}

@Override
public Dependency[] getDependencies() {
return packageProperties.getDependencies();
}

@Override
public AccessControlHandling getACHandling() {
return packageProperties.getACHandling();
}

@Override
public SubPackageHandling getSubPackageHandling() {
return packageProperties.getSubPackageHandling();
}

@Override
public Calendar getDateProperty(final String name) {
return packageProperties.getDateProperty(name);
}

@Override
public String getProperty(String name) {
return packageProperties.getProperty(name);
}

@Override
public PackageType getPackageType() {
return packageProperties.getPackageType();
}

static ArchiveInfImpl readInf(final @NotNull PackageId packageId,
final @NotNull VaultPackage vaultPackage) throws PackageException {
if (!vaultPackage.isValid()) {
throw new PackageException("Package is not valid: " + packageId);
}

return new ArchiveInfImpl(vaultPackage.getProperties(), vaultPackage.getArchive());
}
}
7 changes: 2 additions & 5 deletions core/src/main/java/net/adamcin/oakpal/core/OakMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,12 @@ private void processPackage(Session admin, JcrPackageManager manager, JcrPackage
List<PackageId> subpacks = Arrays.asList(jcrPackage.extractSubpackages(options));

final VaultPackage vaultPackage = jcrPackage.getPackage();
if (!vaultPackage.isValid()) {
throw new PackageException("Package is not valid: " + packageId);
}
final ArchiveInf archiveInf = ArchiveInfImpl.readInf(packageId, vaultPackage);

if (!preInstall) {
progressChecks.forEach(handler -> {
try {
handler.beforeExtract(packageId, inspectSession,
vaultPackage.getProperties(), vaultPackage.getMetaInf(), subpacks);
handler.beforeExtract(packageId, inspectSession, archiveInf, subpacks);
} catch (final Exception e) {
getErrorListener().onListenerException(e, handler, packageId);
}
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/net/adamcin/oakpal/core/ProgressCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ default void readManifest(PackageId packageId, Manifest manifest) {

}

/**
* Called for each package before it is extracted.
*
* @param packageId the package ID of the newly opened package
* @param inspectSession session providing access to repository state
* @param archiveInf the package archive information
* @param subpackages extracted subpackages
* @throws RepositoryException because of access to a {@link Session}
* @since 1.5.0
*/
default void beforeExtract(PackageId packageId, Session inspectSession,
ArchiveInf archiveInf, List<PackageId> subpackages) throws RepositoryException {
this.beforeExtract(packageId, inspectSession, archiveInf, archiveInf.getMetaInf(), subpackages);
}

/**
* Called for each package before it is extracted.
*
Expand All @@ -96,6 +111,8 @@ default void readManifest(PackageId packageId, Manifest manifest) {
* @param metaInf the package meta information
* @param subpackages extracted subpackages
* @throws RepositoryException because of access to a {@link Session}
* @deprecated 1.5.0 this is no longer called directly by OakMachine. Implement
* {@link #beforeExtract(PackageId, Session, ArchiveInf, List)} instead.
*/
default void beforeExtract(PackageId packageId, Session inspectSession, PackageProperties packageProperties,
MetaInf metaInf, List<PackageId> subpackages) throws RepositoryException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ public void readManifest(final PackageId packageId, final Manifest manifest) {
guardHandler(INVOKE_ON_READ_MANIFEST, handle -> handle.apply(packageId, manifest));
}

@Override
public void beforeExtract(final PackageId packageId, final Session inspectSession,
final ArchiveInf archiveInf, final List<PackageId> subpackages)
throws RepositoryException {
guardSessionHandler(INVOKE_ON_BEFORE_EXTRACT, handle -> handle.apply(packageId, inspectSession, archiveInf,
archiveInf.getMetaInf(), subpackages.toArray(new PackageId[0])));
}

@Override
public void beforeExtract(final PackageId packageId, final Session inspectSession,
final PackageProperties packageProperties, final MetaInf metaInf,
Expand Down
Loading

0 comments on commit b9a96a4

Please sign in to comment.