Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of man-page producers. #139

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions docs/maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ tarball archive, or a file. You can add as many data
elements to your dataSet as you'd like. The `data` element has the
following options:

Element | Description | Required
---------------- | ---------------------------------------------------------------------------- | ------------------------------------
src | The directory, tarball, file to include in the package | Yes
dst | New filename at destination (type must be `file`) | No
linkName | The path of the link (type must be `link`) | Yes for link
linkTarget | The target of the link (type must be `link`) | Yes for link
type | Type of the data source. (archive, directory, file, link or template) | No; but will be Yes in the future
missingSrc | Fail if src file/folder is missing (ignore or fail) | No; defaults to `fail`
includes | A comma seperated list of files to include from the directory or tarball | No; defaults to all files
excludes | A comma seperated list of files to exclude from the directory or tarball | No; defaults to no exclutions
conffile | A boolean value to define if the files should be included in the conffiles | No; defaults to `false`
mapper | The files to exclude from the directory or tarball | No
paths/(path..) | One or more string literal paths that will created in the package | No; Yes for type `template`
Element | Description | Required
---------------- | ------------------------------------------------------------------------------- | ------------------------------------
src | The directory, tarball, file, man-page to include in the package | Yes
dst | New filename at destination (type must be `file` or `man-page`) | No
linkName | The path of the link (type must be `link`) | Yes for link
linkTarget | The target of the link (type must be `link`) | Yes for link
type | Type of the data source. (archive, directory, file, link, man-page or template) | No; but will be Yes in the future
missingSrc | Fail if src file/folder is missing (ignore or fail) | No; defaults to `fail`
includes | A comma seperated list of files to include from the directory or tarball | No; defaults to all files
excludes | A comma seperated list of files to exclude from the directory or tarball | No; defaults to no exclutions
conffile | A boolean value to define if the files should be included in the conffiles | No; defaults to `false`
mapper | The files to exclude from the directory or tarball | No
paths/(path..) | One or more string literal paths that will created in the package | No; Yes for type `template`

There are different kinds of mappers that can be selected via the `type` argument. The most common one is the 'perm' mapper.

Expand Down Expand Up @@ -218,6 +218,12 @@ include a directory, a tarball, and a file in your deb package and then sign it
<symlink>true</symlink>
</data>

<!-- Man page example -->
<data>
<type>man-page</type>
<src>/a/path/to/manpage.1</src>
</data>

<!-- Conffiles example -->
<data>
<src>${project.build.directory}/data</src>
Expand All @@ -241,6 +247,7 @@ include a directory, a tarball, and a file in your deb package and then sign it
```
If you don't want to store your key information in the POM you can store this is your settings.xml, here's an example settings.xml:

```xml
<settings>
<profiles>
<profile>
Expand All @@ -256,5 +263,6 @@ If you don't want to store your key information in the POM you can store this is
<activeProfile>jdeb-signing</activeProfile>
</activeProfiles>
</settings>
```

keyring, key and passphrase can then be omitted from the POM entirely.
63 changes: 35 additions & 28 deletions src/main/java/org/vafer/jdeb/ant/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
import java.util.Collection;
import java.util.Iterator;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.PatternSet;
import org.vafer.jdeb.DataConsumer;
import org.vafer.jdeb.DataProducer;
import org.vafer.jdeb.producers.DataProducerArchive;
import org.vafer.jdeb.producers.DataProducerDirectory;
import org.vafer.jdeb.producers.DataProducerFile;
import org.vafer.jdeb.producers.*;

/**
* Ant "data" element acting as a factory for DataProducers.
Expand Down Expand Up @@ -82,36 +81,44 @@ public void produce( final DataConsumer pReceiver ) throws IOException {
throw new FileNotFoundException("Data source not found : " + src);
}

org.vafer.jdeb.mapping.Mapper[] mappers = new org.vafer.jdeb.mapping.Mapper[mapperWrapper.size()];
final org.vafer.jdeb.mapping.Mapper[] mappers = new org.vafer.jdeb.mapping.Mapper[mapperWrapper.size()];
final Iterator<Mapper> it = mapperWrapper.iterator();
for (int i = 0; i < mappers.length; i++) {
mappers[i] = it.next().createMapper();
}

if ("file".equalsIgnoreCase(type)) {
new DataProducerFile(
src,
destinationName,
getIncludePatterns(getProject()),
getExcludePatterns(getProject()),
mappers
).produce(pReceiver);

} else if ("archive".equalsIgnoreCase(type)) {
new DataProducerArchive(
src,
getIncludePatterns(getProject()),
getExcludePatterns(getProject()),
mappers
).produce(pReceiver);

} else if ("directory".equalsIgnoreCase(type)) {
new DataProducerDirectory(
src,
getIncludePatterns(getProject()),
getExcludePatterns(getProject()),
mappers
).produce(pReceiver);
final Project project = getProject();

ProducerFactory.KnownType knownType = ProducerFactory.KnownType.forString(type);

if (knownType == null) {
return;
}

final DataProducer p = ProducerFactory.create(knownType, new ProducerFactory.Params() {
@Override
public File getSource() {
return src;
}
@Override
public String getDestination() {
return destinationName;
}
@Override
public String[] getIncludePatterns() {
return Data.this.getIncludePatterns(project);
}

@Override
public String[] getExcludePatterns() {
return Data.this.getExcludePatterns(project);
}

@Override
public org.vafer.jdeb.mapping.Mapper[] getMappers() {
return mappers;
}
});
p.produce(pReceiver);
}
}
108 changes: 63 additions & 45 deletions src/main/java/org/vafer/jdeb/maven/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.vafer.jdeb.DataConsumer;
import org.vafer.jdeb.DataProducer;
import org.vafer.jdeb.producers.DataProducerArchive;
import org.vafer.jdeb.producers.DataProducerDirectory;
import org.vafer.jdeb.producers.DataProducerFile;
import org.vafer.jdeb.producers.DataProducerLink;
import org.vafer.jdeb.producers.DataProducerPathTemplate;
import org.vafer.jdeb.producers.*;

import static org.vafer.jdeb.maven.MissingSourceBehavior.*;

Expand Down Expand Up @@ -148,62 +144,84 @@ public String[] splitPatterns( String patterns ) {
}

public void produce( final DataConsumer pReceiver ) throws IOException {
org.vafer.jdeb.mapping.Mapper[] mappers = null;
if (mapper != null) {
mappers = new org.vafer.jdeb.mapping.Mapper[] { mapper.createMapper() };
}
final org.vafer.jdeb.mapping.Mapper[] mappers =
mapper == null
? null
: new org.vafer.jdeb.mapping.Mapper[] { mapper.createMapper() };

// link type
ProducerFactory.KnownType knownType = ProducerFactory.KnownType.forString(type);

if ("link".equalsIgnoreCase(type)) {
if (linkName == null) {
throw new RuntimeException("linkName is not set");
}
if (linkTarget == null) {
throw new RuntimeException("linkTarget is not set");
}
if (knownType == null) {
throw new IOException(buildUnknownTypeMessage(type, src));
}

new DataProducerLink(linkName, linkTarget, symlink, includePatterns, excludePatterns, mappers).produce(pReceiver);
return;
if (knownType.requiresSource() && (src == null || !src.exists())) {
if (IGNORE == missingSrc) {
return;
}
throw new FileNotFoundException("Data source not found : " + src);
}

// template type
final DataProducer p = ProducerFactory.create(knownType, new ProducerFactory.Params() {
@Override
public File getSource() {
return src;
}
@Override
public String getDestination() {
return dst;
}
@Override
public String getLink() {
return linkName;
}
@Override
public String getLinkTarget() {
return linkTarget;
}

if ("template".equalsIgnoreCase(type)) {
if (paths == null || paths.length == 0) {
throw new RuntimeException("paths is not set");
@Override
public boolean isSimlink() {
return symlink;
}

new DataProducerPathTemplate(paths, includePatterns, excludePatterns, mappers).produce(pReceiver);
return;
}
@Override
public String[] getTemplatePaths() {
return paths;
}

// Types that require src to exist
@Override
public String[] getIncludePatterns() {
return includePatterns;
}

if (src == null || !src.exists()) {
if (missingSrc == IGNORE) {
return;
} else {
throw new FileNotFoundException("Data source not found : " + src);
@Override
public String[] getExcludePatterns() {
return excludePatterns;
}
}

if ("file".equalsIgnoreCase(type)) {
new DataProducerFile(src, dst, includePatterns, excludePatterns, mappers).produce(pReceiver);
return;
}
@Override
public org.vafer.jdeb.mapping.Mapper[] getMappers() {
return mappers;
}
});

if ("archive".equalsIgnoreCase(type)) {
new DataProducerArchive(src, includePatterns, excludePatterns, mappers).produce(pReceiver);
return;
}
p.produce(pReceiver);
}

if ("directory".equalsIgnoreCase(type)) {
new DataProducerDirectory(src, includePatterns, excludePatterns, mappers).produce(pReceiver);
return;
private static String buildUnknownTypeMessage( final String type,
final File src ) {
final StringBuilder b = new StringBuilder("Unknown type '");
b.append(type).append("' (");
for (ProducerFactory.KnownType t : ProducerFactory.KnownType.values()) {
if (t.ordinal() != 0) {
b.append("|");
}
b.append(t.shortName());
}
b.append(") for ").append(src);
return b.toString();

throw new IOException("Unknown type '" + type + "' (file|directory|archive|template|link) for " + src);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
public abstract class AbstractDataProducer implements DataProducer {

protected final static int ROOT_UID = 0;
protected final static String ROOT_NAME = "root";

private final String[] includes;
private final String[] excludes;
private final Mapper[] mappers;
Expand Down
22 changes: 3 additions & 19 deletions src/main/java/org/vafer/jdeb/producers/DataProducerDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.tools.ant.DirectoryScanner;
Expand Down Expand Up @@ -72,12 +71,7 @@ public void produce( final DataConsumer pReceiver ) throws IOException {
dirname += "/";
}

TarArchiveEntry entry = new TarArchiveEntry(dirname, true);
entry.setUserId(0);
entry.setUserName("root");
entry.setGroupId(0);
entry.setGroupName("root");
entry.setMode(TarArchiveEntry.DEFAULT_DIR_MODE);
TarArchiveEntry entry = Producers.defaultDirEntryWithName(dirname);

entry = map(entry);

Expand All @@ -99,23 +93,13 @@ public void produce( final DataConsumer pReceiver ) throws IOException {
filename = filename.replace(File.separatorChar, '/');
}

TarArchiveEntry entry = new TarArchiveEntry(filename, true);
entry.setUserId(0);
entry.setUserName("root");
entry.setGroupId(0);
entry.setGroupName("root");
entry.setMode(TarArchiveEntry.DEFAULT_FILE_MODE);
TarArchiveEntry entry = Producers.defaultFileEntryWithName(filename);

entry = map(entry);

entry.setSize(file.length());

final InputStream inputStream = new FileInputStream(file);
try {
pReceiver.onEachFile(inputStream, entry.getName(), entry.getLinkName(), entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode(), entry.getSize());
} finally {
inputStream.close();
}
Producers.produceInputStreamWithEntry(pReceiver, new FileInputStream(file), entry);
}
}

Expand Down
15 changes: 2 additions & 13 deletions src/main/java/org/vafer/jdeb/producers/DataProducerFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.vafer.jdeb.DataConsumer;
Expand Down Expand Up @@ -51,23 +50,13 @@ public void produce( final DataConsumer pReceiver ) throws IOException {
fileName = file.getName();
}

TarArchiveEntry entry = new TarArchiveEntry(fileName, true);
entry.setUserId(0);
entry.setUserName("root");
entry.setGroupId(0);
entry.setGroupName("root");
entry.setMode(TarArchiveEntry.DEFAULT_FILE_MODE);
TarArchiveEntry entry = Producers.defaultFileEntryWithName(fileName);

entry = map(entry);

entry.setSize(file.length());

final InputStream inputStream = new FileInputStream(file);
try {
pReceiver.onEachFile(inputStream, entry.getName(), entry.getLinkName(), entry.getUserName(), entry.getUserId(), entry.getGroupName(), entry.getGroupId(), entry.getMode(), entry.getSize());
} finally {
inputStream.close();
}
Producers.produceInputStreamWithEntry(pReceiver, new FileInputStream(file), entry);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public DataProducerFileSet( final FileSet fileset ) {
}

public void produce( final DataConsumer pReceiver ) throws IOException {
String user = "root";
int uid = 0;
String group = "root";
int gid = 0;
String user = Producers.ROOT_NAME;
int uid = Producers.ROOT_UID;
String group = Producers.ROOT_NAME;
int gid = Producers.ROOT_UID;
int filemode = TarEntry.DEFAULT_FILE_MODE;
int dirmode = TarEntry.DEFAULT_DIR_MODE;
String prefix = "";
Expand Down
Loading