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

binary control files #220

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>jdeb</artifactId>
<packaging>maven-plugin</packaging>
<name>jdeb</name>
<version>1.4</version>
<version>1.4.1</version>
<description>
This library provides an Ant task and a Maven plugin to create Debian packages from Java builds in a truly cross
platform manner. Build your Debian packages on any platform that has Java support. Windows, Linux, OS X - it doesn't
Expand Down Expand Up @@ -187,7 +187,7 @@
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<!-- settingsFile>src/it/settings.xml</settingsFile -->
<goals>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make the tests work in my environment. Quick hack for me, Do not merge this, sorry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But probably hard to implement. I think you detect variables withing string - and have to encode them for saving the resulting file.

Another approach would be a configurable method you call before closing the tar file. I'd add my binary file in this method. And make my method availabe to your Code by adding a dependency to the Plugin config in my pom.

<goal>clean</goal>
<goal>package</goal>
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/org/vafer/jdeb/ControlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.vafer.jdeb;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -103,13 +104,19 @@ void buildControl(BinaryPackageControlFile packageControlFile, File[] controlFil
if ("conffiles".equals(file.getName())) {
foundConffiles = true;
}

if (CONFIGURATION_FILENAMES.contains(file.getName()) || MAINTAINER_SCRIPTS.contains(file.getName())) {
FilteredFile configurationFile = new FilteredFile(new FileInputStream(file), resolver);
configurationFile.setOpenToken(openReplaceToken);
configurationFile.setCloseToken(closeReplaceToken);
addControlEntry(file.getName(), configurationFile.toString(), outputStream);

} else if (file.getName().endsWith(".bin")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly speaking I am not such a fan of adding some new rule about the file name. Maybe we should just make this work with https://github.com/mlhartme/jdeb/blob/binanry_control/src/main/java/org/vafer/jdeb/ControlBuilder.java#L120 instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I though about that too, but i didn't see a reliable way to detect binary files. In my case, the file is a shell script with a jar file appended.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the proper way to fix this is expanding https://github.com/tcurdt/jdeb/blob/master/src/main/java/org/vafer/jdeb/utils/InformationInputStream.java

Right now we are only checking for the BOM and the shebang. We could also also try to detect a binary there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can you properly check for a binary there? Character codes >= 128?

And by the way: what about shell scripts with "here documents" http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04. Maybe they have a similar problem.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't use BOM and Shebang but plain heuristics we indeed run into those problems with "here documents", too.

I am wondering if we should take a step back here. Right now we have 2 types

  • shell - where we apply variable expansion
  • other - which we just copy without applying variable expansion

Introducing a 3rd type is a bit sneaky as we would want to have variable expansion on only the shell part of the combined file.

So question is whether there is another way to ship the jar but appending it to the shell script or having some kind of convention/marker that tells jdeb where to apply the variable expansion and what to copy as binary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of an alternative place for the jar: is has to be present when postrm is executed. And at this point dpkg has removed all other files of the package. Even e.g. prerm.

Is there a way to define a variables with my binary content?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not binary variables yet - but that's actually a very (!) interesting line of thinking to solve this.

InputStream in = new FileInputStream(file);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Utils.copy(in, out);
in.close();
out.close();
addControlEntry(file.getName().substring(0, file.getName().length() - 4), out.toByteArray(), outputStream);
} else if (!"control".equals(file.getName())) {
// initialize the information stream to guess the type of the file
InformationInputStream infoStream = new InformationInputStream(new FileInputStream(file));
Expand Down Expand Up @@ -209,23 +216,25 @@ public BinaryPackageControlFile createPackageControlFile(File file, BigInteger p


private static void addControlEntry(final String pName, final String pContent, final TarArchiveOutputStream pOutput) throws IOException {
final byte[] data = pContent.getBytes("UTF-8");
addControlEntry(pName, pContent.getBytes("UTF-8"), pOutput);
}

private static void addControlEntry(final String pName, final byte[] pData, final TarArchiveOutputStream pOutput) throws IOException {
final TarArchiveEntry entry = new TarArchiveEntry("./" + pName, true);
entry.setSize(data.length);
entry.setSize(pData.length);
entry.setNames("root", "root");

if (MAINTAINER_SCRIPTS.contains(pName)) {
entry.setMode(PermMapper.toMode("755"));
} else {
entry.setMode(PermMapper.toMode("644"));
}

pOutput.putArchiveEntry(entry);
pOutput.write(data);
pOutput.write(pData);
pOutput.closeArchiveEntry();
}

/**
* Tells if the specified directory is ignored by default (.svn, cvs, etc)
*
Expand Down