package org.argeo.slc.rpmfactory.core;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.io.IOUtils;
-import org.springframework.core.io.Resource;
-
public class RpmSpecFile {
- private Resource specFile;
+ private Path specFile;
private String name;
private String version;
private Map<String, String> sources = new HashMap<String, String>();
private Map<String, String> patches = new HashMap<String, String>();
- public RpmSpecFile(Resource specFile) {
+ public RpmSpecFile(Path specFile) {
this.specFile = specFile;
parseSpecFile();
}
parseSpecFile();
}
- @SuppressWarnings("unchecked")
protected void parseSpecFile() {
try {
- List<String> lines = (List<String>) IOUtils.readLines(specFile
- .getInputStream());
+ List<String> lines = (List<String>) Files.readAllLines(specFile);
lines: for (String line : lines) {
int indexSemiColon = line.indexOf(':');
return buf.toString();
}
- public Resource getSpecFile() {
+ public Path getSpecFile() {
return specFile;
}
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.SlcException;
-import org.springframework.core.io.Resource;
/**
* Reads the output of a 'yum list all' command and interpret the list of
/** Not installed but available */
private Set<String> installable = new TreeSet<String>();
- private Resource yumListOutput;
+ private Path yumListOutput;
public void init() {
- try {
- if (yumListOutput != null) {
- load(yumListOutput.getInputStream());
+ if (yumListOutput != null) {
+ try (InputStream in = Files.newInputStream(yumListOutput)) {
+ load(in);
if (log.isDebugEnabled())
- log.debug(installed.size() + " installed, "
- + installable.size() + " installable, from "
+ log.debug(installed.size() + " installed, " + installable.size() + " installable, from "
+ yumListOutput);
+ } catch (IOException e) {
+ throw new SlcException("Cannot initialize yum list parser", e);
}
- } catch (IOException e) {
- throw new SlcException("Cannot initialize yum list parser", e);
}
}
return installable.contains(packageName);
}
- protected void load(InputStream in) {
- try {
- Boolean readingInstalled = false;
- Boolean readingAvailable = false;
- LineIterator it = IOUtils.lineIterator(in, "UTF-8");
- while (it.hasNext()) {
- String line = it.nextLine();
- if (line.trim().equals("Installed Packages")) {
- readingInstalled = true;
- } else if (line.trim().equals("Available Packages")) {
- readingAvailable = true;
- readingInstalled = false;
- } else if (readingAvailable) {
- if (Character.isLetterOrDigit(line.charAt(0))) {
- installable.add(extractRpmName(line));
- }
- } else if (readingInstalled) {
- if (Character.isLetterOrDigit(line.charAt(0))) {
- installed.add(extractRpmName(line));
- }
+ protected void load(InputStream in) throws IOException {
+ Boolean readingInstalled = false;
+ Boolean readingAvailable = false;
+ LineIterator it = IOUtils.lineIterator(in, "UTF-8");
+ while (it.hasNext()) {
+ String line = it.nextLine();
+ if (line.trim().equals("Installed Packages")) {
+ readingInstalled = true;
+ } else if (line.trim().equals("Available Packages")) {
+ readingAvailable = true;
+ readingInstalled = false;
+ } else if (readingAvailable) {
+ if (Character.isLetterOrDigit(line.charAt(0))) {
+ installable.add(extractRpmName(line));
+ }
+ } else if (readingInstalled) {
+ if (Character.isLetterOrDigit(line.charAt(0))) {
+ installed.add(extractRpmName(line));
}
}
- } catch (IOException e) {
- throw new SlcException("Cannot load yum list output", e);
- } finally {
- IOUtils.closeQuietly(in);
}
}
String packageName = st.nextToken();
// consider the arch as an extension
return FilenameUtils.getBaseName(packageName);
- //return packageName.split("\\.")[0];
+ // return packageName.split("\\.")[0];
}
public Set<String> getInstalled() {
return installable;
}
- public void setYumListOutput(Resource yumListOutput) {
+ public void setYumListOutput(Path yumListOutput) {
this.yumListOutput = yumListOutput;
}