0

I've tried a few variations on the implementation syntax which I believe is incorrect below. I'm not quite sure that I have the correct repository for this dependency, either.

running gradle:

thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ rm -rf $HOME/.gradle/caches/
thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ gradle clean

BUILD SUCCESSFUL in 769ms
1 actionable task: 1 up-to-date
thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ gradle clean build

> Task :compileJava
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:4: error: package net.sf.expectit.matcher does not exist
import static net.sf.expectit.matcher.Matchers.contains;
                                     ^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:4: error: static import only from classes and interfaces
import static net.sf.expectit.matcher.Matchers.contains;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:5: error: package net.sf.expectit.matcher does not exist
import static net.sf.expectit.matcher.Matchers.eof;
                                     ^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:5: error: static import only from classes and interfaces
import static net.sf.expectit.matcher.Matchers.eof;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:6: error: package net.sf.expectit.matcher does not exist
import static net.sf.expectit.matcher.Matchers.regexp;
                                     ^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:6: error: static import only from classes and interfaces
import static net.sf.expectit.matcher.Matchers.regexp;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:24: error: cannot find symbol
        Expect expect = new ExpectBuilder()
        ^
  symbol:   class Expect
  location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:24: error: cannot find symbol
        Expect expect = new ExpectBuilder()
                            ^
  symbol:   class ExpectBuilder
  location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:32: error: cannot find symbol
        expect.expect(contains("Press Return to continue"));
                      ^
  symbol:   method contains(String)
  location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:34: error: cannot find symbol
        expect.expect(contains("forecast city code--"));
                      ^
  symbol:   method contains(String)
  location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:36: error: cannot find symbol
        expect.expect(contains("X to exit:"));
                      ^
  symbol:   method contains(String)
  location: class App
11 errors

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
2 actionable tasks: 1 executed, 1 up-to-date
thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ gradle -v

------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------

Build time:   2020-03-24 19:52:07 UTC
Revision:     bacd40b727b0130eeac8855ae3f9fd9a0b207c60

Kotlin:       1.3.70
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.7 (AdoptOpenJDK 11.0.7+10)
OS:           Linux 5.4.0-29-generic amd64

thufir@dur:~/NetBeansProjects/expect$ 

code:

package expect;

import java.util.logging.Logger;
import static net.sf.expectit.matcher.Matchers.contains;
import static net.sf.expectit.matcher.Matchers.eof;
import static net.sf.expectit.matcher.Matchers.regexp;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class App {

    private final static Logger log = Logger.getLogger(App.class.getName());

    public static void main(String[] args) {
        new App().telnet();
    }

    private void telnet() {
        log.info("foo");

        Process process = Runtime.getRuntime().exec("telnet rainmaker.wunderground.com");

        StringBuilder wholeBuffer = new StringBuilder();
        Expect expect = new ExpectBuilder()
                .withOutput(process.getOutputStream())
                .withInputs(process.getInputStream())
                .withEchoOutput(wholeBuffer)
                .withEchoInput(wholeBuffer)
                .withExceptionOnFailure()
                .build();

        expect.expect(contains("Press Return to continue"));
        expect.sendLine();
        expect.expect(contains("forecast city code--"));
        expect.sendLine("SAN");
        expect.expect(contains("X to exit:"));
        expect.sendLine();

        String response = wholeBuffer.toString();
        System.out.println(response);

        expect.close();

    }

}

build file:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.3/userguide/tutorial_java_projects.html
 */

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

    // Apply the application plugin to add support for building a CLI application.
    id 'application'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}

dependencies {
    // This dependency is used by the application.
    implementation 'com.google.guava:guava:28.2-jre'

    // Use TestNG framework, also requires calling test.useTestNG() below
    testImplementation 'org.testng:testng:7.0.0'  


    // https://mvnrepository.com/artifact/net.sf.expectit/expectit-core
//    implementation 'net.sf.expectit' name 'expectit-core', version '0.9.0'
//    implementation 'net.sf.expectit' name: 'expectit-core', version: '0.9.0'


}

application {
    // Define the main class for the application.
    mainClassName = 'expect.App'
}

test {
    // Use TestNG for unit tests
    useTestNG()
}
6
  • 1
    try mavenCentral() repository
    – smac89
    May 13, 2020 at 3:35
  • Yeah, no luck with that. I'm trying to clear the cache, see that it downloads, etc. I think that's probably the problem, though -- something like that.
    – Thufir
    May 13, 2020 at 4:53
  • 1
    What is your gradle version? Also can you try using implementation instead of compile
    – smac89
    May 13, 2020 at 5:08
  • I updated the question, @smac89 and am looking at implementation
    – Thufir
    May 13, 2020 at 5:29
  • 1
    I'm not sure what the problem is. I just tried your code and without mavenCentral() repo, it works for me. I used implementation 'net.sf.expectit:expectit-core:0.9.0'
    – smac89
    May 13, 2020 at 5:46

1 Answer 1

1

runs:

package expectit;

import java.util.logging.Logger;
import static net.sf.expectit.matcher.Matchers.contains;
import static net.sf.expectit.matcher.Matchers.eof;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class App {

    private final static Logger log = Logger.getLogger(App.class.getName());

    public static void main(String[] args) throws IOException {
        new App().telnet();
    }

    private void telnet() throws IOException {
        log.info("foo");

        Process process = Runtime.getRuntime().exec("telnet rainmaker.wunderground.com");

        StringBuilder wholeBuffer = new StringBuilder();
        net.sf.expectit.Expect expect = new net.sf.expectit.ExpectBuilder()
                .withOutput(process.getOutputStream())
                .withInputs(process.getInputStream())
                .withEchoOutput(wholeBuffer)
                .withEchoInput(wholeBuffer)
                .withExceptionOnFailure()
                .build();

        expect.expect(contains("Press Return to continue"));
        expect.sendLine();
        expect.expect(contains("forecast city code--"));
        expect.sendLine("SAN");
        expect.expect(contains("X to exit:"));
        expect.sendLine();

        String response = wholeBuffer.toString();
        System.out.println(response);

        expect.close();

    }

}

https://github.com/THUFIR/expectit

thanks smac89

2
  • 1
    Glad it's working for you now. If you did anything special to make it work, don't forget to include that in your answer
    – smac89
    May 13, 2020 at 19:28
  • rather than using an import statement I used the fully qualified class and interface names as above...but I think that had more with using gradle 6 when NB works with gradle 5. Otherwise, dunno.
    – Thufir
    May 13, 2020 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.