Skip to content

Commit 81046e7

Browse files
committed
fixes
1 parent c6c60fa commit 81046e7

File tree

6 files changed

+41
-15
lines changed

6 files changed

+41
-15
lines changed

pear-java-api/src/main/java/org/phpmaven/pear/library/IPearUtility.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public interface IPearUtility {
120120
/**
121121
* Adds a pear channel.
122122
*
123-
* @param channel channel.xml file.
123+
* @param channel path to channel.xml file.
124124
* @return the pear channel.
125125
*
126126
* @throws PhpException thrown on php execution errors.

pear-java-impl/src/main/java/org/phpmaven/pear/library/impl/Package.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ public void install(IPackageVersion version, boolean forceUninstall,
193193
" is not known.");
194194
}
195195

196+
this.pearUtility.executePearCmd("channel-update " + this.pearChannel.getName());
197+
this.pearUtility.executePearCmd("clear-cache");
198+
196199
if (this.installedVersion != null) {
197200
if (version.getVersion() == null
198201
|| this.installedVersion.getVersion().getPearVersion().equals(

pear-java-impl/src/test/java/org/phpmaven/pear/library/test/BaseTest.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import junit.framework.Assert;
3737

38-
import org.apache.commons.logging.Log;
3938
import org.codehaus.plexus.util.FileUtils;
4039
import org.codehaus.plexus.util.IOUtil;
4140
import org.junit.Test;
@@ -63,9 +62,10 @@ public class BaseTest extends AbstractTestCase {
6362
*/
6463
@Test
6564
public void testChannelXml() throws Exception {
65+
unzipPearNet();
6666
final IPearUtility util = getPearUtility(false);
6767

68-
final File pearFolder = new File("pear.php.net").getAbsoluteFile();
68+
final File pearFolder = new File("target/pear.php.net").getAbsoluteFile();
6969
final IPearChannel channel = util.channelDiscoverLocal(pearFolder);
7070
Assert.assertNotNull(channel);
7171
Assert.assertNotNull(channel.getPrimaryServer());
@@ -251,12 +251,13 @@ public void testVersionData() throws Exception {
251251
*/
252252
@Test
253253
public void testPackageInstallation() throws Exception {
254-
final IPearChannel channel = getChannel(true);
255-
final IPackage pkg = channel.getPackage("Auth");
256-
final IPackageVersion version = pkg.getVersion("1.6.4");
254+
final IPearUtility util = getPearUtility(true, true);
255+
final IPearChannel channel = util.lookupChannel("pear");
256+
final IPackage pkg = channel.getPackage("Validate_AT");
257+
final IPackageVersion version = pkg.getVersion("0.5.2");
257258
Assert.assertNull(pkg.getInstalledVersion());
258259
version.install();
259-
Assert.assertEquals("1.6.4", pkg.getInstalledVersion().getVersion().getPearVersion());
260+
Assert.assertEquals("0.5.2", pkg.getInstalledVersion().getVersion().getPearVersion());
260261

261262
Assert.assertTrue(
262263
channel.getPearUtility().getPhpDir().getAbsolutePath().startsWith(
@@ -312,7 +313,7 @@ public void testVersionMapping() throws Exception {
312313
Assert.assertEquals("1.5.0-RC1", PackageHelper.convertPearVersionToMavenVersion("1.5.0RC1"));
313314
Assert.assertEquals("1.3.0-r3", PackageHelper.convertPearVersionToMavenVersion("1.3.0r3"));
314315
Assert.assertEquals("2.0.0-dev1", PackageHelper.convertPearVersionToMavenVersion("2.0.0dev1"));
315-
Assert.assertEquals("1.2.2beta1", PackageHelper.convertPearVersionToMavenVersion("1.2.2-beta-1"));
316+
Assert.assertEquals("1.2.2-beta-1", PackageHelper.convertPearVersionToMavenVersion("1.2.2beta1"));
316317
Assert.assertEquals("0.9.7-dev", PackageHelper.convertPearVersionToMavenVersion("0.9.7dev"));
317318
Assert.assertEquals("0.5.2-beta", PackageHelper.convertPearVersionToMavenVersion("0.5.2beta"));
318319
Assert.assertEquals("1.4-beta-1", PackageHelper.convertPearVersionToMavenVersion("1.4b1"));
@@ -408,24 +409,33 @@ public void testFileLayoutV2() throws Exception {
408409
*/
409410
private IPearChannel getChannel(final boolean install)
410411
throws Exception {
412+
unzipPearNet();
411413
final IPearUtility util = getPearUtility(install);
412414

413-
final File pearFolder = new File("pear.php.net").getAbsoluteFile();
415+
final File pearFolder = new File("target/pear.php.net").getAbsoluteFile();
414416
final IPearChannel channel = util.channelDiscoverLocal(pearFolder);
415417
return channel;
416418
}
417419

420+
private void unzipPearNet() throws IOException {
421+
final File target = new File("target/pear.php.net");
422+
if (!target.exists()) {
423+
target.mkdirs();
424+
final File pearZip = new File(
425+
"target/test-classes/org/phpmaven/pear/library/test/pear.php.net.zip");
426+
unzip(pearZip, target.getParentFile());
427+
}
428+
}
429+
418430
/**
419431
* Unpacks a zip file.
420432
*
421-
* @param log Logging
422433
* @param zipFile the zip file
423434
* @param destDir the destination directory
424435
* @throws IOException if something goes wrong
425436
*/
426-
private void unzip(Log log, File zipFile, File destDir) throws IOException {
437+
private void unzip(File zipFile, File destDir) throws IOException {
427438
final ZipFile zip = new ZipFile(zipFile);
428-
log.debug("unzip " + zipFile.getAbsolutePath());
429439

430440
final Enumeration<? extends ZipEntry> items = zip.entries();
431441
while (items.hasMoreElements()) {
@@ -476,7 +486,19 @@ private void unpackZipEntry(ZipEntry zipEntry, InputStream zipEntryInputStream,
476486
* @return
477487
* @throws Exception
478488
*/
479-
private IPearUtility getPearUtility(final boolean install)
489+
private IPearUtility getPearUtility(final boolean install)
490+
throws Exception {
491+
return this.getPearUtility(install, false);
492+
}
493+
494+
/**
495+
* Returns the pear utility.
496+
* @param install
497+
* @return
498+
* @throws Exception
499+
*/
500+
@SuppressWarnings("unchecked")
501+
private IPearUtility getPearUtility(final boolean install, final boolean upgrade)
480502
throws Exception {
481503
final File testDir = new File("target/test").getAbsoluteFile();
482504
FileUtils.deleteDirectory(testDir);
@@ -489,7 +511,7 @@ private IPearUtility getPearUtility(final boolean install)
489511
}
490512

491513
if (install) {
492-
util.installPear(false);
514+
util.installPear(upgrade);
493515
}
494516
return util;
495517
}

pear-java-impl/src/test/java/org/phpmaven/pear/library/test/ChannelAddTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class ChannelAddTest extends AbstractTestCase {
4040
*
4141
* @throws Exception thrown on errors
4242
*/
43-
public void testChannelAdd() throws Exception {
43+
@SuppressWarnings("unchecked")
44+
public void testChannelAdd() throws Exception {
4445
final File testDir = new File("target/test").getAbsoluteFile();
4546
FileUtils.deleteDirectory(testDir);
4647
testDir.mkdirs();
Binary file not shown.

0 commit comments

Comments
 (0)